1
Fork 0
do-not-zip/README.md

51 lines
1.6 KiB
Markdown
Raw Normal View History

2018-04-19 16:25:25 +00:00
# do-not-zip
2018-04-19 21:12:36 +00:00
[![npm version](https://img.shields.io/npm/v/do-not-zip.svg?style=flat-square)](https://www.npmjs.com/package/do-not-zip)
2018-04-19 16:25:25 +00:00
Do not zip. Just store.
## What
2018-09-25 21:39:02 +00:00
Stick some text files into a zip file. This library is super simple and small because it just stores the files without compressing them, which is often sufficient when all you want to do is let the user download some files generated in the browser. Works on the server (Node.js) and on the client (JavaScript). Requires ES2015+.
2018-04-19 16:25:25 +00:00
2018-09-25 21:39:02 +00:00
## How
2018-04-19 16:25:25 +00:00
```javascript
import * as doNotZip from 'do-not-zip';
2019-03-21 21:19:00 +00:00
// on the server or the client:
const byteArray = doNotZip.toArray([
// each file should have:
// - 'path' - a string
// - 'data' - a string, or an array of bytes or Uint8Array or Buffer or anything else that gives integers when indexed
2018-04-19 17:02:01 +00:00
{ path: 'path/to/file1.txt', data: 'Hello' },
{ path: 'another/file2.txt', data: 'World' },
2018-09-25 21:39:02 +00:00
{ path: 'yet/another/file3.bin', data: [1, 2, 3, 4, 5] },
2019-03-21 21:19:00 +00:00
// ...
2018-04-19 17:02:01 +00:00
]);
// => output will be an array of bytes
2019-03-21 21:19:00 +00:00
// on the server:
const buffer = doNotZip.toBuffer([ ... ]);
// => output will be a Buffer
// on the client:
const blob = doNotZip.toBlob([ ... ]);
// => output will be a Blob
// on the server or the client:
const bufferOrBlob = doNotZip.toAuto([ ... ]);
// => output will be a Buffer on the server and a Blob on the client
// (which one to return is determined by whether there is a Blob global defined)
2018-04-19 16:25:25 +00:00
```
## Thanks
2018-04-19 17:02:01 +00:00
- https://github.com/mrananyan/ZipperJS
- https://users.cs.jmu.edu/buchhofp/forensics/formats/pkzip.html
- https://stackoverflow.com/a/18639999
2018-04-19 16:25:25 +00:00
## License
2019-03-21 21:19:00 +00:00
[MIT](LICENSE)