-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
42 lines (34 loc) · 1.03 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';
var stream = require('stream'),
util = require('util'),
duplexify = require('duplexify'),
jsonstream = require('JSONStream');
/*
* function PublishSplitStream ()
* Splits out the tarball portion of an "npm publish" request
*/
module.exports = function PublishSplitStream() {
if (!(this instanceof PublishSplitStream)) { return new PublishSplitStream(); }
var self = this;
this.stream = duplexify();
var parser = jsonstream.parse('_attachments.*.data');
parser.on('data', function (d) {
self.stream.setReadable(new Content(new Buffer(d, 'base64')));
});
this.stream.setWritable(parser);
return this.stream;
};
/*
* A simple readable stream for passing through a buffer
* that has already been read into memory
*/
function Content(str) {
stream.Readable.call(this);
this.push(Array.isArray(str) ? str.join('') : str);
this.push(null);
}
//
// Inherit from Readable Stream and provide a _read stub.
//
util.inherits(Content, stream.Readable);
Content.prototype._read = function noop() {};