This repository was archived by the owner on Aug 12, 2020. It is now read-only.
This repository was archived by the owner on Aug 12, 2020. It is now read-only.
Setting offset in catReadableStream results in incorrect stream length #229
Closed
Description
The following example doesn't give the expected result:
const Ipfs = require('ipfs')
const videoCid = 'QmcPZGXSyaQSnDVEtJrgtp2EyxhENiBdpGa8pfs5rMBCWr' // sintel.mp4
const fs = require('fs')
const offset = 48
const ipfs = new Ipfs()
ipfs.on('ready', () => {
let numDone = 0
const s1Data = []
const s2Data = []
const s1 = ipfs.files.catReadableStream(videoCid, {
offset: 0
})
s1.on('data', (buf) => {
s1Data.push(buf)
})
s1.on('end', () => {
if (++numDone === 2) {
checkResult()
}
})
const s2 = ipfs.files.catReadableStream(videoCid, {
offset: offset
})
s2.on('data', (buf) => {
s2Data.push(buf)
})
s2.on('end', () => {
if (++numDone === 2) {
checkResult()
}
})
function checkResult () {
const b1 = Buffer.concat(s1Data).slice(offset)
const b2 = Buffer.concat(s2Data)
const eq = b1.equals(b2)
console.log('length 1', b1.length)
console.log('length 2', b2.length)
console.log('equal?', eq)
process.exit(eq ? 0 : 1)
}
})
Metadata
Metadata
Assignees
Labels
No labels