Skip to content

Commit 481634a

Browse files
Update index.js
1 parent 7fb0577 commit 481634a

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const _ = require('lodash')
4+
const Duplex = require('stream').Duplex
45

56
class HlsjsIPFSLoader {
67
constructor(config) {
@@ -90,6 +91,7 @@ function getFile(ipfs, rootHash, filename, callback) {
9091
console.log("Received stream for file '" + rootHash + "/" +
9192
fileName + "'")
9293
if (err) return callback(err)
94+
stream = buf2Stream(stream)
9395
stream.on('data', function (chunk) {
9496
console.log("Received " + chunk.length + " bytes for file '" +
9597
rootHash + "/" + fileName + "'")
@@ -110,4 +112,11 @@ function buf2str(buf) {
110112
return String.fromCharCode.apply(null, new Uint8Array(buf))
111113
}
112114

115+
function buf2Stream(buffer) {
116+
let stream = new Duplex()
117+
stream.push(buffer)
118+
stream.push(null)
119+
return stream
120+
}
121+
113122
exports = module.exports = HlsjsIPFSLoader

0 commit comments

Comments
 (0)