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.
- Loading branch information
1 parent
812ec2e
commit 607623d
Showing
7 changed files
with
209 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,75 @@ | ||
'use strict' | ||
|
||
const mfs = require('ipfs-mfs/core') | ||
const toPullStream = require('async-iterator-to-pull-stream') | ||
const toReadableStream = require('async-iterator-to-stream') | ||
const all = require('async-iterator-all') | ||
const callbackify = require('util').callbackify | ||
const PassThrough = require('stream').PassThrough | ||
const pull = require('pull-stream/pull') | ||
const map = require('pull-stream/throughs/map') | ||
|
||
module.exports = self => mfs({ | ||
ipld: self._ipld, | ||
repo: self._repo, | ||
repoOwner: self._options.repoOwner | ||
}) | ||
const mapLsFile = (options = {}) => { | ||
const long = options.long || options.l | ||
|
||
return (file) => { | ||
console.info(file) | ||
|
||
return { | ||
hash: long ? file.cid.toBaseEncodedString(options.cidBase) : '', | ||
name: file.name, | ||
type: long ? file.type : 0, | ||
size: long ? file.size || 0 : 0 | ||
} | ||
} | ||
} | ||
|
||
module.exports = self => { | ||
const methods = mfs({ | ||
ipld: self._ipld, | ||
blocks: self._blockService, | ||
datastore: self._repo.root, | ||
repoOwner: self._options.repoOwner | ||
}) | ||
|
||
return { | ||
cp: callbackify(methods.cp), | ||
flush: callbackify(methods.flush), | ||
ls: callbackify(async (path, options) => { | ||
const files = await all(methods.ls(path, options)) | ||
|
||
return files.map(mapLsFile(options)) | ||
}), | ||
lsReadableStream: (path, options) => { | ||
const stream = toReadableStream.obj(methods.ls(path, options)) | ||
const through = new PassThrough({ | ||
objectMode: true | ||
}) | ||
stream.on('data', (file) => through.emit('data', mapLsFile(options)(file))) | ||
stream.on('error', through.emit.bind(through, 'error')) | ||
stream.on('end', through.emit.bind(through, 'end')) | ||
|
||
return through | ||
}, | ||
lsPullStream: (path, options) => { | ||
return pull( | ||
toPullStream.source(methods.ls(path, options)), | ||
map(mapLsFile(options)) | ||
) | ||
}, | ||
mkdir: callbackify(methods.mkdir), | ||
mv: callbackify(methods.mv), | ||
read: callbackify(async (path, options) => { | ||
return Buffer.concat(await all(methods.read(path, options))) | ||
}), | ||
readPullStream: (path, options) => { | ||
return toReadableStream(methods.read(path, options)) | ||
}, | ||
readReadableStream: (path, options) => { | ||
return toPullStream.source(methods.read(path, options)) | ||
}, | ||
rm: callbackify(methods.rm), | ||
stat: callbackify(methods.stat), | ||
write: callbackify(methods.write) | ||
} | ||
} |
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
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.