diff --git a/TransportIPFS.js b/TransportIPFS.js index 095bbb7..93399d6 100644 --- a/TransportIPFS.js +++ b/TransportIPFS.js @@ -62,7 +62,7 @@ class TransportIPFS extends Transport { this.options = options; // Dictionary of options { ipfs: {...}, "yarrays", yarray: {...} } this.name = "IPFS"; // For console log etc this.supportURLs = ['ipfs']; - this.supportFunctions = ['fetch', 'store']; // Does not support reverse, createReadStream fails on files uploaded with urlstore TODO reenable when Kyle fixes urlstore + this.supportFunctions = ['fetch', 'store', 'createReadStream']; // Does not support reverse this.status = Transport.STATUS_LOADED; } @@ -297,7 +297,7 @@ class TransportIPFS extends Transport { return TransportIPFS.urlFrom(res); } - // Based on https://github.com/ipfs/js-ipfs/pull/1231/files + /* OLD WAY Based on https://github.com/ipfs/js-ipfs/pull/1231/files async p_offsetStream(stream, links, startByte, endByte) { let streamPosition = 0 @@ -345,9 +345,8 @@ class TransportIPFS extends Transport { function crs(opts) { // This is a synchronous function // Return a readable stream that provides the bytes between offsets "start" and "end" inclusive console.log("opts=",JSON.stringify(opts)); - /* Can replace rest of crs with this when https://github.com/ipfs/js-ipfs/pull/1231/files lands (hopefully v0.28.3) - return self.ipfs.catReadableStream(mh, opts ? opts.start : 0, opts && opts.end) ? opts.end+1 : undefined) - */ + // Can replace rest of crs with this when https://github.com/ipfs/js-ipfs/pull/1231/files lands (hopefully v0.28.3) + // return self.ipfs.catReadableStream(mh, opts ? opts.start : 0, opts && opts.end) ? opts.end+1 : undefined) if (!opts) return throughstream; //TODO-STREAM unclear why called without opts - take this out when figured out if (throughstream && throughstream.destroy) throughstream.destroy(); throughstream = new stream.PassThrough(); @@ -361,6 +360,82 @@ class TransportIPFS extends Transport { } return crs; } + */ + + async p_f_createReadStream(url, {verbose=false, wanturl=false}={}) { + /* + Fetch bytes progressively, using a node.js readable stream, based on a url of the form: + No assumption is made about the data in terms of size or structure. + + This is the initialisation step, which returns a function suitable for