From 54804f4a642176134fa835eca86a047a87a704d2 Mon Sep 17 00:00:00 2001 From: otofune Date: Tue, 14 Nov 2017 04:11:53 +0900 Subject: [PATCH] =?UTF-8?q?add-file-to-drive=20-=20hash=E3=81=8Cstream?= =?UTF-8?q?=E3=82=92=E5=8F=97=E3=81=91=E3=82=8B=E6=99=82=E3=80=81hash?= =?UTF-8?q?=E3=82=82=E3=81=BE=E3=81=9Fstream=E3=81=AA=E3=81=AE=E3=81=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/common/add-file-to-drive.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/api/common/add-file-to-drive.ts b/src/api/common/add-file-to-drive.ts index 1aa21f71a..5f7d255e4 100644 --- a/src/api/common/add-file-to-drive.ts +++ b/src/api/common/add-file-to-drive.ts @@ -94,13 +94,16 @@ export default ( ((): Promise => new Promise((res, rej) => { const readable = fs.createReadStream(path); const hash = crypto.createHash('md5'); + const chunks = []; readable .on('error', rej) - .on('end', () => { - res(hash.digest('hex')); - }) .pipe(hash) - .on('error', rej); + .on('error', rej) + .on('data', (chunk) => chunks.push(chunk)) + .on('end', () => { + const buffer = Buffer.concat(chunks); + res(buffer.toString('hex')); + }); }))(), // mime ((): Promise<[string, string | null]> => new Promise((res, rej) => {