adm-zip icon indicating copy to clipboard operation
adm-zip copied to clipboard

Is the buffer based constructor stable?

Open otakustay opened this issue 9 years ago • 2 comments

From wiki it is said AdmZip constructor only accepts parameter of type string, but in source code it also accepts a Buffer object, is this function stable or will it be removed sometime?

We need the Buffer based one in order to read file async

otakustay avatar Dec 08 '15 06:12 otakustay

FWIW, reading data from a Buffer worked for me 😄

My particular use case is working with the Github Actions API to download an artifact (zipped JSON file), and parse it into memory. I'd rather not have to write+read to disk, if I can avoid it.


@iacobnasca can I propose the following update to the ADM-ZIP Wiki Page?

constructor(filePathOrBuffer)

The class constructor can have one or no arguments specified. If an argument of type String is provided, the class will try to read the file at filePath and parse it as a zip.

If a Buffer is provided, the class will try to parse the data as a zip file.

If no argument is specified, then a new in memory zip will be created.

Examples:

// loads and parses existing zip file local_file.zip
var zip = new Zip("local_file.zip"); 

// loads and parses zip data from a Buffer
var buffer = fs.readFileSync("local_file.zip");
var zip = new Zip(buffer);

// creates new in memory zip
var zip = new Zip();

eschwartz avatar Dec 08 '20 15:12 eschwartz

There is an issue on node 12 and 14 (Not sure if other versions are the same) when passing a buffer to the constructor if fails. because is testing to see if the buffer is and instance of Uinit8Array

if (!(input instanceof Uint8Array))

Buffer is not and that fails the check and the initialization of the zip.

jers73 avatar Aug 31 '21 23:08 jers73