compressing icon indicating copy to clipboard operation
compressing copied to clipboard

`gzip.uncompress()` to `original_file_name` from gzip metadata

Open Araxeus opened this issue 1 month ago • 3 comments

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?

Araxeus avatar Dec 03 '25 20:12 Araxeus

Can you provide a way to reproduce it?

fengmk2 avatar Dec 03 '25 23:12 fengmk2

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:

  1. (if FLG.FNAME set) original_file_name
  2. (If FLG.FNAME not 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.

Araxeus avatar Dec 04 '25 11:12 Araxeus

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.

fengmk2 avatar Dec 04 '25 13:12 fengmk2