Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: drop hexo-util#HashStream #4279

Merged
merged 1 commit into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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