From 09316c28f43d2824aba19132ae18ad606da0d2d6 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Fri, 20 Dec 2019 20:05:25 +0800 Subject: [PATCH] refactor(console/generate): utilize hexo-util --- lib/plugins/console/generate.js | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/lib/plugins/console/generate.js b/lib/plugins/console/generate.js index 5ba5de61c8..a5225ce90a 100644 --- a/lib/plugins/console/generate.js +++ b/lib/plugins/console/generate.js @@ -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; @@ -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;