Skip to content

gzip.uncompress() to original_file_name from gzip metadata #120

Description

@Araxeus

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?

Activity

  1. fengmk2 commented on Dec 3, 2025

    @fengmk2
    Member

    Can you provide a way to reproduce it?

  2. Araxeus commented on Dec 4, 2025

    @Araxeus
    Author

    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.

  3. changed the title [-]gzip uncompress file name[/-] [+]`gzip.uncompress()` to `original_file_name` from gzip metadata[/+] on Dec 4, 2025
  4. fengmk2 commented on Dec 4, 2025

    @fengmk2
    Member

    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.

  5. added theissue type on Dec 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions