This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implementing the new interfaces (#619)
- Loading branch information
Showing
21 changed files
with
522 additions
and
413 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict' | ||
|
||
const addCmd = require('./add.js') | ||
const pull = require('pull-stream') | ||
const pushable = require('pull-pushable') | ||
|
||
module.exports = (send) => { | ||
const add = addCmd(send) | ||
|
||
return (options) => { | ||
options = options || {} | ||
|
||
const source = pushable() | ||
const sink = pull.collect((err, tuples) => { | ||
if (err) { return source.end(err) } | ||
|
||
add(tuples, options, (err, filesAdded) => { | ||
if (err) { return source.end(err) } | ||
|
||
filesAdded.forEach((file) => source.push(file)) | ||
source.end() | ||
}) | ||
}) | ||
|
||
return { | ||
sink: sink, | ||
source: source | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict' | ||
|
||
const addCmd = require('./add.js') | ||
const Duplex = require('readable-stream').Duplex | ||
|
||
module.exports = (send) => { | ||
const add = addCmd(send) | ||
|
||
return (options) => { | ||
options = options || {} | ||
|
||
const tuples = [] | ||
|
||
const ds = new Duplex({ objectMode: true }) | ||
ds._read = (n) => {} | ||
|
||
ds._write = (file, enc, next) => { | ||
tuples.push(file) | ||
next() | ||
} | ||
|
||
ds.end = () => add(tuples, options, (err, res) => { | ||
if (err) { return ds.emit('error', err) } | ||
|
||
res.forEach((tuple) => ds.push(tuple)) | ||
ds.push(null) | ||
}) | ||
|
||
return ds | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict' | ||
|
||
const cleanCID = require('../utils/clean-cid') | ||
const v = require('is-ipfs') | ||
const toPull = require('stream-to-pull-stream') | ||
const deferred = require('pull-defer') | ||
|
||
module.exports = (send) => { | ||
return (hash, opts) => { | ||
opts = opts || {} | ||
|
||
const p = deferred.source() | ||
|
||
try { | ||
hash = cleanCID(hash) | ||
} catch (err) { | ||
if (!v.ipfsPath(hash)) { | ||
return p.end(err) | ||
} | ||
} | ||
|
||
send({ path: 'cat', args: hash, buffer: opts.buffer }, (err, stream) => { | ||
if (err) { return p.end(err) } | ||
|
||
p.resolve(toPull(stream)) | ||
}) | ||
|
||
return p | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict' | ||
|
||
const cleanCID = require('../utils/clean-cid') | ||
const v = require('is-ipfs') | ||
const Stream = require('readable-stream') | ||
const pump = require('pump') | ||
|
||
module.exports = (send) => { | ||
return (hash, opts) => { | ||
opts = opts || {} | ||
|
||
const pt = new Stream.PassThrough() | ||
|
||
try { | ||
hash = cleanCID(hash) | ||
} catch (err) { | ||
if (!v.ipfsPath(hash)) { | ||
return pt.destroy(err) | ||
} | ||
} | ||
|
||
send({ path: 'cat', args: hash, buffer: opts.buffer }, (err, stream) => { | ||
if (err) { return pt.destroy(err) } | ||
|
||
pump(stream, pt) | ||
}) | ||
|
||
return pt | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict' | ||
|
||
const cleanCID = require('../utils/clean-cid') | ||
const TarStreamToObjects = require('../utils/tar-stream-to-objects') | ||
const v = require('is-ipfs') | ||
const through = require('through2') | ||
const pull = require('pull-stream') | ||
const toPull = require('stream-to-pull-stream') | ||
const deferred = require('pull-defer') | ||
|
||
module.exports = (send) => { | ||
return (path, opts) => { | ||
opts = opts || {} | ||
|
||
const p = deferred.source() | ||
|
||
try { | ||
path = cleanCID(path) | ||
} catch (err) { | ||
if (!v.ipfsPath(path)) { | ||
return p.end(err) | ||
} | ||
} | ||
|
||
const request = { path: 'get', args: path, qs: opts } | ||
|
||
// Convert the response stream to TarStream objects | ||
send.andTransform(request, TarStreamToObjects, (err, stream) => { | ||
if (err) { return p.end(err) } | ||
|
||
const files = [] | ||
stream.pipe(through.obj((file, enc, next) => { | ||
if (file.content) { | ||
files.push({ path: file.path, content: toPull(file.content) }) | ||
} else { | ||
files.push(file) | ||
} | ||
next() | ||
}, () => p.resolve(pull.values(files)))) | ||
}) | ||
|
||
return p | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict' | ||
|
||
const cleanCID = require('../utils/clean-cid') | ||
const TarStreamToObjects = require('../utils/tar-stream-to-objects') | ||
const v = require('is-ipfs') | ||
const Stream = require('readable-stream') | ||
const pump = require('pump') | ||
|
||
module.exports = (send) => { | ||
return (path, opts) => { | ||
opts = opts || {} | ||
|
||
const pt = new Stream.PassThrough({objectMode: true}) | ||
|
||
try { | ||
path = cleanCID(path) | ||
} catch (err) { | ||
if (!v.ipfsPath(path)) { | ||
return pt.destroy(err) | ||
} | ||
} | ||
|
||
const request = { path: 'get', args: path, qs: opts } | ||
|
||
// Convert the response stream to TarStream objects | ||
send.andTransform(request, TarStreamToObjects, (err, stream) => { | ||
if (err) { return pt.destroy(err) } | ||
|
||
pump(stream, pt) | ||
}) | ||
|
||
return pt | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.