Skip to content

Commit

Permalink
refactor: drop hexo-util#HashStream (#4279)
Browse files Browse the repository at this point in the history
Replace with hexo-util#createSha1Hash
  • Loading branch information
SukkaW committed Apr 27, 2020
1 parent 2cca1db commit 5c6985a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/box/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { join, sep } = require('path');
const Promise = require('bluebird');
const File = require('./file');
const { Pattern, HashStream } = require('hexo-util');
const { Pattern, createSha1Hash } = require('hexo-util');
const { createReadStream, readdir, stat, watch } = require('hexo-fs');
const { magenta } = require('chalk');
const { EventEmitter } = require('events');
Expand Down Expand Up @@ -238,11 +238,11 @@ function escapeBackslash(path) {
function getHash(path) {
return new Promise((resolve, reject) => {
const src = createReadStream(path);
const hasher = new HashStream();
const hasher = createSha1Hash();

src.pipe(hasher)
.on('finish', () => {
resolve(hasher.read().toString('hex'));
resolve(hasher.digest('hex'));
})
.on('error', reject);
});
Expand Down
6 changes: 3 additions & 3 deletions lib/plugins/console/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const prettyHrtime = require('pretty-hrtime');
const { cyan, magenta } = require('chalk');
const tildify = require('tildify');
const { PassThrough } = require('stream');
const { CacheStream, HashStream } = require('hexo-util');
const { CacheStream, createSha1Hash } = require('hexo-util');

function generateConsole(args = {}) {
const force = args.f || args.force;
Expand Down Expand Up @@ -42,12 +42,12 @@ function generateConsole(args = {}) {
const cacheId = `public/${path}`;
const dataStream = wrapDataStream(route.get(path), bail);
const cacheStream = new CacheStream();
const hashStream = new HashStream();
const hashStream = createSha1Hash();

// Get data => Cache data => Calculate hash
return pipeStream(dataStream, cacheStream, hashStream).then(() => {
const cache = Cache.findById(cacheId);
const hash = hashStream.read().toString('hex');
const hash = hashStream.digest('hex');

// Skip generating if hash is unchanged
if (!force && cache && cache.hash === hash) {
Expand Down

0 comments on commit 5c6985a

Please sign in to comment.