`gzip.uncompress()` to `original_file_name` from gzip metadata
Say I have the following scenario:
I have a test.gz archive that contains one unknown file (lets say its coolFilename.txt), and I don't know the name of the file inside
How do i extract the file inside while keeping its name?
with the current api, i have to provide an output file name, so how can I extract the file inside the gzip while keeping its original name?
its actually even worse than just a naming issue, what if i dont know the type of the file inside? how do I know what extension should the file have?
Can you provide a way to reproduce it?
What I'm asking is for something akin to gzip --decompress--name \ -N, or in other words to be able to supply compressing.gzip.uncompress() with a directory name like compressing.zip.uncompress()
Here's an example:
bash:
echo "console.log('hi')" > script.js
gzip script.js
mv script.js.gz output.gz
ls
# output.gz
gzip --decompress --keep --name output.gz
ls
# output.gz
# script.js
js:
// [1] Cant uncompress into a dir unlike the gzip cli
compressing.gzip.uncompress('output.gz', './result'); // node error "open EISDIR"
// [2] Cant reliably uncompress into a file unless you know the file name inside the gzip
compressing.gzip.uncompress('output.gz', './result/output'); // ok but you just lost the original filename and extension
// [3] Can only reliably uncompress if you already know the filename inside the gzip
compressing.gzip.uncompress('output.gz', './result/script.js'); // ok but i might not know the name and extension of the gzipped file
Ideally compressing.gzip.uncompress() should be able to accept a dir path like in example [1] - and then automatically get the output file name from:
- (if
FLG.FNAMEset)original_file_name - (If
FLG.FNAMEnot set)archive_name.replace(/\.gz$/, "");(Might need a better idea for streams and buffers)
Note: Gzip can (and does by default) store filename metadata. See section 2.3 Member Format in RFC 1952.
I understand that we need to parse the hidden default filename inside the gzip file.
This is a feature worth trying to implement. You are welcome to participate in open source contributions through pull requests.