Security News
Highlights from the 2024 Rails Community Survey
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
compressing
Advanced tools
The missing compress and uncompress lib for node.
Currently uncompressing has not been supported yet.
Currently supported:
npm install compressing
Use gzip as an example, tar, tgz and zip is same as gzip.
promise style
const compressing = require('compressing');
// compress a file
compressing.gzip.compressFile('file/path/to/compress', 'path/to/destination.gz')
.then(compressDone)
.catch(handleError);
// compress a file buffer
compressing.gzip.compressFile(buffer, 'path/to/destination.gz')
.then(compressDone)
.catch(handleError);
// compress a stream
compressing.gzip.compressFile(stream, 'path/to/destination.gz')
.then(compressDone)
.catch(handleError);
stream style
const compressing = require('compressing');
new compressing.gzip.FileStream({ source: 'file/path/to/compress' })
.on('error', handleError)
.pipe(fs.createWriteStream('path/to/destination.gz'))
.on('error', handleError);
// It's a transform stream, so you can pipe to it
fs.createReadStream('file/path/to/compress')
.on('error', handleError)
.pipe(new compressing.gzip.FileStream())
.on('error', handleError)
.pipe(fs.createWriteStream('path/to/destination.gz'))
.on('error', handleError);
// You should take care of stream errors in caution, use multipipe to handle error in one place
const pipe = require('multipipe';)
const sourceStream = fs.createReadStream('file/path/to/compress')
const gzipStream = new compressing.gzip.FileStream();
const destStream = fs.createWriteStream('path/to/destination.gz');
pipe(sourceStream, gzipStream, destStream, err => handleError);
Use tar as an example, tgz and zip is same as gzip.
Gzip only support compressing a single file. if you want to compress a dir with gzip, then you may need tgz instead.
promise style
const compressing = require('compressing');
compressing.tar.compressDir('dir/path/to/compress', 'path/to/destination.tar')
.then(compressDone)
.catch(handleError);
stream style
const compressing = require('compressing');
const tarStream = new compressing.tar.Stream();
tarStream.addEntry('dir/path/to/compress');
tarStream
.on('error', handleError)
.pipe(fs.createWriteStream('path/to/destination.tar'))
.on('error', handleError);
// You should take care of stream errors in caution, use multipipe to handle error in one place
const tarStream = new compressing.tar.Stream();
tarStream.addEntry('dir/path/to/compress');
const destStream = fs.createWriteStream('path/to/destination.tar');
pipe(tarStream, destStream, handleError);
Stream is very powerful, you can compress multiple entries in it;
const tarStream = new compressing.tar.Stream();
// dir
tarStream.addEntry('dir/path/to/compress');
// file
tarStream.addEntry('file/path/to/compress');
// buffer
tarStream.addEntry(buffer);
// stream
tarStream.addEntry(stream);
const destStream = fs.createWriteStream('path/to/destination.tar');
pipe(tarStream, destStream, handleError);
Use this API to compress a single file. This is a convenient method, which wraps FileStream API below, but you can handle error in one place.
Params
/path/to/xx.tgz
), or a writable stream.Returns a promise object.
Use this API to compress a dir. This is a convenient method, which wraps Stream API below, but you can handle error in one place.
Note: gzip do not have a compressDir method, you may need tgz instead.
Params
/path/to/xx.tgz
), or a writable stream.The transform stream to compress a single file.
Note: If you are not very familiar with streams, just use compressFile() API, error can be handled in one place.
Common params:
Gzip params:
Tar params:
Tgz params:
tgz.FileStream is a combination of tar.FileStream and gzip.FileStream, so the params are the combination of params of tar and gzip.
Zip params:
The readable stream to compress anything as you need.
Note: If you are not very familiar with streams, just use compressFile() and compressDir() API, error can be handled in one place.
Gzip only support compressing a single file. So gzip.Stream is not available.
Constructor
No options in all constructors.
Instance methods
Params
FAQs
Everything you need for compressing and uncompressing
The npm package compressing receives a total of 47,785 weekly downloads. As such, compressing popularity was classified as popular.
We found that compressing demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.