summaryrefslogtreecommitdiff
path: root/src/api/common
diff options
context:
space:
mode:
authorotofune <otofune@gmail.com>2017-11-14 04:11:53 +0900
committerotofune <otofune@gmail.com>2017-11-14 04:11:53 +0900
commit54804f4a642176134fa835eca86a047a87a704d2 (patch)
treebf275ab32869b74e832b50dbdbba402d3e0b477f /src/api/common
parentadd-file-to-drive - gmに渡す引数を正しくする (diff)
downloadsharkey-54804f4a642176134fa835eca86a047a87a704d2.tar.gz
sharkey-54804f4a642176134fa835eca86a047a87a704d2.tar.bz2
sharkey-54804f4a642176134fa835eca86a047a87a704d2.zip
add-file-to-drive - hashがstreamを受ける時、hashもまたstreamなのだ
Diffstat (limited to 'src/api/common')
-rw-r--r--src/api/common/add-file-to-drive.ts11
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) => {