Skip to content

Commit 030cee7

Browse files
committed
fix(file): include integrity hash for streamed tarballs too
1 parent 89f17f4 commit 030cee7

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/fetchers/file.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const BB = require('bluebird')
55
const cacache = require('cacache')
66
const Fetcher = require('../fetch')
77
const fs = require('fs')
8-
const pipe = require('mississippi').pipe
8+
const pipe = BB.promisify(require('mississippi').pipe)
99
const through = require('mississippi').through
1010

1111
const readFileAsync = BB.promisify(fs.readFile)
@@ -50,7 +50,19 @@ Fetcher.impl(fetchFile, {
5050
})
5151
})
5252
} else {
53-
return pipe(fs.createReadStream(src), stream)
53+
let integrity
54+
const cacheWriter = !opts.cache
55+
? BB.resolve(null)
56+
: (pipe(
57+
fs.createReadStream(src),
58+
cacache.put.stream(opts.cache, `pacote:tarball:${src}`, {
59+
integrity: opts.integrity
60+
}).on('integrity', d => { integrity = d })
61+
))
62+
return cacheWriter.then(() => {
63+
if (integrity) { stream.emit('integrity', integrity) }
64+
return pipe(fs.createReadStream(src), stream)
65+
})
5466
}
5567
}, err => stream.emit('error', err))
5668
return stream

0 commit comments

Comments
 (0)