hexo/node_modules/hexo-util/lib/cache_stream.js

25 lines
425 B
JavaScript
Raw Normal View History

2023-09-25 15:58:56 +08:00
'use strict';
const { Transform } = require('stream');
class CacheStream extends Transform {
constructor() {
super();
this._cache = [];
}
_transform(chunk, enc, callback) {
const buf = chunk instanceof Buffer ? chunk : Buffer.from(chunk, enc);
this._cache.push(buf);
this.push(buf);
callback();
}
getCache() {
return Buffer.concat(this._cache);
}
}
module.exports = CacheStream;