diff options
| author | otofune <otofune@gmail.com> | 2017-11-14 04:11:53 +0900 |
|---|---|---|
| committer | otofune <otofune@gmail.com> | 2017-11-14 04:11:53 +0900 |
| commit | 54804f4a642176134fa835eca86a047a87a704d2 (patch) | |
| tree | bf275ab32869b74e832b50dbdbba402d3e0b477f /src/api | |
| parent | add-file-to-drive - gmに渡す引数を正しくする (diff) | |
| download | sharkey-54804f4a642176134fa835eca86a047a87a704d2.tar.gz sharkey-54804f4a642176134fa835eca86a047a87a704d2.tar.bz2 sharkey-54804f4a642176134fa835eca86a047a87a704d2.zip | |
add-file-to-drive - hashがstreamを受ける時、hashもまたstreamなのだ
Diffstat (limited to 'src/api')
| -rw-r--r-- | src/api/common/add-file-to-drive.ts | 11 |
1 files 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 1aa21f71ad..5f7d255e4b 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<string> => 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) => { |