kibertoad / unzipomatic

Modern unzipping library for Node.js
MIT License
3 stars 0 forks source link

Design the new API #4

Closed H4ad closed 5 months ago

H4ad commented 5 months ago

Based on https://github.com/thejoshwolfe/yauzl, which is the library we will start from, let's discuss what could be the new API for it.

Some points:

At least to discuss the high level, we can create a TypeScript interface and then we can refactor the code aiming at that interface.

kibertoad commented 5 months ago

I will work on a PR with proposal, but high level thoughts so far:

1) I would start with Promise API to begin with, fully synchronous API has questionable value in the age of async/await; 2) Extracting to a folder should be supported; 3) Extracting to a stream probably should be supported for single-item archives. I'm not sure if it's possible to implement in a sensible way for multi-file archives; 4) Files, streams, buffers and blobs should be supported as input; 5) I don't see benefits from having a stateful entity here, it looks more like a one-off operation, so function with parameters seem a more natural fit for me.

Does it make sense for you?

What benefits do you see from using Generators?

H4ad commented 5 months ago
  1. I would start with Promise API to begin with, fully synchronous API has questionable value in the age of async/await;

I suggested it because sync APIs are usually faster, and in some cases, easier to work with (especially on commonjs). But I'm not against starting with Promise API, we can add it later if needed.

  1. I don't see benefits from having a stateful entity here, it looks more like a one-off operation, so function with parameters seems a more natural fit for me.

I usually like having the API exposed as a class, so I can create the new Unzipomatic with the input and then use the method to get the information I need.

What benefits do you see from using Generators?

Is easy to consume via for loop when you don't want to get all the filenames at once (as list), or await/async inside a loop to get the next item in the zip.

kibertoad commented 5 months ago

Generator makes sense for listing and extracting data as a readable, then. I don't see benefits for extracting to fs one file at a time

DaniGuardiola commented 5 months ago

Just my 2 cents, but the thing I need the most as a user is a simple method that turns a directory into a zip file, with the same dir structure. I suspect this is gonna be one of the main use cases as well. I haven't had time to catch up with all of the movement in this repo so pardon me if this is already contemplated.

kibertoad commented 5 months ago

@DaniGuardiola key goal of this project is unzipping. for zipping there are some fairly good libraries out there, I believe. we can do deeper analysis for it after unzipping part is done and see if it needs to be covered or not