Skip to content
This repository was archived by the owner on Mar 8, 2024. It is now read-only.

Commit 4a9f4d5

Browse files
author
Henry Rodrick
authored
Merge pull request #7 from alanshaw/fix/upgrade-for-0.34
fix: upgrade for 0.34
2 parents f0df3ff + e6d43b7 commit 4a9f4d5

File tree

2 files changed

+17
-32
lines changed

2 files changed

+17
-32
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"homepage": "https://github.com/moshisushi/hlsjs-ipfs-loader#readme",
1919
"dependencies": {
2020
"aegir": "^11.0.2",
21-
"gulp": "^3.9.1",
22-
"lodash": "^4.17.4"
21+
"gulp": "^3.9.1"
2322
}
2423
}

src/index.js

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
'use strict'
22

3-
const _ = require('lodash')
4-
const Duplex = require('stream').Duplex
5-
63
class HlsjsIPFSLoader {
74
constructor(config) {
85
this.ipfs = config.ipfs
@@ -67,9 +64,9 @@ function getFile(ipfs, rootHash, filename, callback) {
6764
var hash = null
6865
var fileSize, fileName
6966

70-
_.each(res.links, function(link) {
67+
res.links.forEach(function(link) {
7168
if (link.name === filename) {
72-
hash = link.multihash
69+
hash = link.cid.toString()
7370
fileSize = link.size
7471
fileName = link.name
7572
return false
@@ -87,36 +84,25 @@ function getFile(ipfs, rootHash, filename, callback) {
8784
var bufView = new Uint8Array(resBuf)
8885
var offs = 0
8986

90-
ipfs.files.cat(hash, function (err, stream) {
91-
console.log("Received stream for file '" + rootHash + "/" +
92-
fileName + "'")
93-
if (err) return callback(err)
94-
stream = buf2Stream(stream)
95-
stream.on('data', function (chunk) {
96-
console.log("Received " + chunk.length + " bytes for file '" +
97-
rootHash + "/" + fileName + "'")
98-
bufView.set(chunk, offs)
99-
offs += chunk.length
100-
});
101-
stream.on('error', function (err) {
102-
callback(err, null)
103-
});
104-
stream.on('end', function () {
105-
callback(null, resBuf)
106-
});
107-
})
87+
const stream = ipfs.catReadableStream(hash)
88+
console.log("Received stream for file '" + rootHash + "/" + fileName + "'")
89+
stream.on('data', function (chunk) {
90+
console.log("Received " + chunk.length + " bytes for file '" +
91+
rootHash + "/" + fileName + "'")
92+
bufView.set(chunk, offs)
93+
offs += chunk.length
94+
});
95+
stream.on('error', function (err) {
96+
callback(err, null)
97+
});
98+
stream.on('end', function () {
99+
callback(null, resBuf)
100+
});
108101
});
109102
}
110103

111104
function buf2str(buf) {
112105
return String.fromCharCode.apply(null, new Uint8Array(buf))
113106
}
114107

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

0 commit comments

Comments
 (0)