v
v copied to clipboard
szip: zip_files() and zip_folder() should have options to change the used compression level
Describe the feature
The two functions zip_files and zip_folder should have an option to control the level of compression. Right now in both functions the compression level is hard coded with ".no_compression.
Use Case
The two functions now work like "tar" - they just create a single file that's not compressed. But when I read "zip" I always expect that the resultfile is compressed. Now I have to fiddle around with the details of szip instead of just using it.
Proposed Solution
For zip_folder I tried the following two changes - and they seamed to work. For zip_files there must be done some more work but it should be very likely:
--- a/vlib/szip/szip.v
+++ b/vlib/szip/szip.v
@@ -8,6 +8,7 @@ import os
[params]
pub struct ZipFolderOptions {
omit_empty_folders bool
+ compression_level CompressionLevel = .no_compression
}
struct C.zip_t {
@@ -273,7 +274,7 @@ pub fn zip_folder(folder string, zip_file string, opt ZipFolderOptions) ! {
})
// open or create new zip
- mut zip := open(zip_file, .no_compression, .write)!
+ mut zip := open(zip_file, opt.compression_level, .write)!
// close zip
defer {
zip.close()
```
### Other Information
_No response_
### Acknowledgements
- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
### Version used
V full version: V 0.3.3 a6bf20f.9794a23
### Environment details (OS name and version, etc.)
I did a "v up" before creating this issue.
V full version: V 0.3.3 a6bf20f.9794a23
PRs are always welcome! However, I would change
compression_level CompressionLevel = .no_compression
to the actual Zip default (6, isn't it? Whatever enum that corresponds to...).