Skip to content

Commit

Permalink
refactor(console/generate): utilize hexo-util
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Dec 20, 2019
1 parent a381dda commit 09316c2
Showing 1 changed file with 2 additions and 26 deletions.
28 changes: 2 additions & 26 deletions lib/plugins/console/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const Promise = require('bluebird');
const prettyHrtime = require('pretty-hrtime');
const { cyan, magenta } = require('chalk');
const tildify = require('tildify');
const { Transform, PassThrough } = require('stream');
const { HashStream } = require('hexo-util');
const { PassThrough } = require('stream');
const { CacheStream, HashStream } = require('hexo-util');

function generateConsole(args = {}) {
const force = args.f || args.force;
Expand Down Expand Up @@ -178,28 +178,4 @@ function pipeStream(...args) {
});
}

function CacheStream() {
Reflect.apply(Transform, this, []);

this._cache = [];
}

require('util').inherits(CacheStream, Transform);

CacheStream.prototype._transform = function(chunk, enc, callback) {
const buf = chunk instanceof Buffer ? chunk : Buffer.from(chunk, enc);

this._cache.push(buf);
this.push(buf);
callback();
};

CacheStream.prototype.destroy = function() {
this._cache.length = 0;
};

CacheStream.prototype.getCache = function() {
return Buffer.concat(this._cache);
};

module.exports = generateConsole;

0 comments on commit 09316c2

Please sign in to comment.