https://github.com/indexzero/npm-package-buffer
Buffers entries from a tar.Parse() stream for an npm package into memory
https://github.com/indexzero/npm-package-buffer
Last synced: 11 months ago
JSON representation
Buffers entries from a tar.Parse() stream for an npm package into memory
- Host: GitHub
- URL: https://github.com/indexzero/npm-package-buffer
- Owner: indexzero
- License: mit
- Created: 2015-07-20T19:41:04.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-07-21T07:31:28.000Z (almost 11 years ago)
- Last Synced: 2025-06-10T01:06:47.778Z (about 1 year ago)
- Language: JavaScript
- Size: 162 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# npm-package-buffer
Buffers entries from a tar.Parse() stream for an npm package into memory
## Usage
``` js
var fs = require('fs');
var zlib = require('zlib');
var tar = require('tar');
var PackageBuffer = require('npm-package-buffer');
var parser = tar.Parse();
var buffer = new PackageBuffer(parser)
.on('error', function (err) { console.log ('tar error: %s', err); })
.on('end', function () {
//
// Log fully read the package.json
// aliased to `.pkg` as well.
//
console.dir(buffer.package);
console.dir(buffer.pkg);
//
// Log all our files in memory
//
console.dir(buffer.files);
});
//
// Read our tarball and pipe it to the tar parser.
//
fs.createReadStream('any-npm-package-1.2.3.tgz')
.pipe(zlib.Unzip())
.on('error', function (err) { console.log('zlib error: %s', err); })
.pipe(parser);
```
### API
See also: [`tar-buffer`](https://github.com/indexzero/tar-buffer).
#### Options
- `log`: (optional) Log function to use. Expects `console.log` API.
#### Why isn't this a proper stream?
Underneath the covers, `tar` emits several events, not just `data` events which have to be handled seprately from a traditional stream.