zippen
is a small and easy to use zip generator. It can be used to pack multiple files / buffers into one .zip file / buffer.
This package was built based on the pkware .ZIP File Format Specification.
const Zip = require('@cloudacy/zippen').Zip
import {Zip} from '@cloudacy/zippen'
const zip = new Zip()
- path -
string
: The location of the file to be stored in the .zip file (may also contain directories: e.g.foo/bar.txt
) - last modified date -
Date
: A date object, holding the last modified date of the file or directory - data -
Buffer | undefined
: If the entry is a file, this should be a buffer, holding the uncompressed data. If it is a directory, passundefined
here.
zip.addEntry('foo.txt', new Date(), Buffer.from('bar'))
This will return the resulting .zip buffer.
zip.build()
write
will store the resulting .zip file at the given file path.
- path -
string | number | Buffer | URL
: The location of the resulting .zip file.
zip.write('foo.zip')
const zip = new Zip()
zip.addEntry('foo.txt', new Date(), Buffer.from('bar'))
zip.write('foo.zip')
local file header 1
encryption header 1
file data 1
data descriptor 1
- ...
local file header n
encryption header n
file data n
data descriptor n
archive decryption header
archive extra data record
central directory header 1
- ...
central directory header n
zip64 end of central directory record
zip64 end of central directory locator
end of central directory record
The following example is a hexdump of a .zip file, holding one file, called abc.txt
with the content abc\n
. The file was generated by a macOS 10.14.2 system.
All parts of the .zip file were grouped to the pieces of a .zip file. The bytes were also grouped by their meaning, based on the specification.
- local file header signature:
50 4b 03 04
- version needed to extract:
14 00
- general purpose bit flag:
08 00
- compression algorithm:
08 00
- last mod file time (MSDOS format):
6b 81
- last mod file date (MSDOS format):
8f 4d
- crc-32:
00 00 00 00
- compressed size:
00 00 00 00
- uncompressed size:
00 00 00 00
- file name length:
07 00
- extra field length:
10 00
- file name:
61 62 63 2e 74 78 74
- ASCII:abc.txt
- compressed data:
4b 4c 4a e6 02 00
- data descriptor signature (unofficial):
50 4b 07 08
- crc-32:
4e 81 88 47
- compressed size:
06 00 00 00
- uncompressed size:
04 00 00 00
- central file header signature:
50 4b 01 02
- version made by:
15 03
- version needed to extract:
14 00
- general purpose bit flag:
08 00
- compression method:
08 00
- last mod file time (MSDOS format):
6b 81
- last mod file date (MSDOS format):
8f 4d
- crc-32:
4e 81 88 47
- compressed size:
06 00 00 00
- uncompressed size:
04 00 00 00
- file name length:
07 00
- extra field length:
00 00
- file comment length:
00 00
- disk number start:
00 00
- internal file attributes:
00 00
- external file attributes:
00 40 a4 81
- relative offset of local header:
00 00 00 00
- file name:
61 62 63 2e 74 78 74
- ASCII:abc.txt
- end of central directories signature:
50 4b 05 06
- disk number:
00 00
- disk number:
00 00
- number of entries:
01 00
- number of entries on this disk:
01 00
- size of central directory block(s):
41 00 00 00
- offset of central directory block(s):
4b 00 00 00
- comment length:
00 00