-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulp-utils.js
49 lines (39 loc) · 1.09 KB
/
gulp-utils.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
43
44
45
46
47
48
49
const { Readable, Transform } = require('stream');
const https = require('https');
const path = require('path');
module.exports.getLocalPath = function getLocalPath(filename) {
return path.resolve(process.cwd(), filename);
};
module.exports.streamToBuffer = function streamToBuffer(stream) {
return new Promise((resolve) => {
const chunks = [];
stream.on('data', chunk => chunks.push(chunk));
stream.on('end', () => resolve(Buffer.concat(chunks)));
});
};
module.exports.HttpsReadable = class HttpsReadable extends Readable {
constructor(options) {
super();
https.request(options, (res) => {
res.on('data', chunk => this.push(chunk));
res.on('end', () => this.push(null));
}).end();
}
_read() {} // eslint-disable-line class-methods-use-this
};
module.exports.CombineIntoArray = class CombineIntoArray extends Transform {
constructor() {
super({
objectMode: true,
});
this._items = [];
}
_transform(chunk, encoding, cb) {
this._items.push(chunk);
cb(null);
}
_flush(cb) {
this.push(this._items);
cb(null);
}
};