From 1b94a511ccaf95e8c8e6e350cadaee51d41332c8 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 16 Feb 2017 16:38:59 +0100 Subject: [PATCH] Explicitly set default encoding in createHash() Up until now, the default encoding for this is `binary`, but this is scheduled to change in Node 8. Since this module is currently always passing string input to the `Hash` object, it needs to account for that. A better fix would likely involve dropping all strings handling and treating binary data using Buffer objects, but I kept this change minimal to avoid any breakage. Refs: https://github.com/nodejs/node/pull/8611 --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 2cc4528..30f92f7 100644 --- a/index.js +++ b/index.js @@ -138,7 +138,7 @@ class ChecksumValidator { let fullPath = path.resolve(baseDir, filename) debug(`Reading file with "${this.encoding(binary)}" encoding`) let stream = fs.createReadStream(fullPath, {encoding: this.encoding(binary)}) - let hasher = crypto.createHash(this.algorithm) + let hasher = crypto.createHash(this.algorithm, {defaultEncoding: 'binary'}) hasher.on('readable', () => { let data = hasher.read() if (data) {