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
Showing
10 changed files
with
401 additions
and
27 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,48 @@ | ||
'use strict' | ||
|
||
const Command = require('ronin').Command | ||
const debug = require('debug') | ||
const utils = require('../../utils') | ||
const log = debug('cli:files') | ||
log.error = debug('cli:files:error') | ||
|
||
module.exports = Command.extend({ | ||
desc: 'Download IPFS objects', | ||
|
||
options: {}, | ||
|
||
run: (path, options) => { | ||
if (!path) { | ||
throw new Error("Argument 'path' is required") | ||
} | ||
if (!options) { | ||
options = {} | ||
} | ||
utils.getIPFS((err, ipfs) => { | ||
if (err) { | ||
throw err | ||
} | ||
if (utils.isDaemonOn()) { | ||
throw new Error('on-line mode is not supported yet') | ||
/* ipfs.cat(path, (err, res) => { | ||
if (err) { | ||
throw (err) | ||
} | ||
console.log(res.toString()) | ||
}) | ||
return */ | ||
} | ||
|
||
ipfs.files.cat(path, (err, res) => { | ||
if (err) { | ||
throw (err) | ||
} | ||
if (res) { | ||
res.on('file', (data) => { | ||
data.stream.pipe(process.stdout) | ||
}) | ||
} | ||
}) | ||
}) | ||
} | ||
}) |
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,69 @@ | ||
'use strict' | ||
|
||
const Command = require('ronin').Command | ||
const debug = require('debug') | ||
const utils = require('../../utils') | ||
const log = debug('cli:files') | ||
log.error = debug('cli:files:error') | ||
var fs = require('fs') | ||
const pathj = require('path') | ||
|
||
module.exports = Command.extend({ | ||
desc: 'Download IPFS objects', | ||
|
||
options: {}, | ||
|
||
run: (path, options) => { | ||
let dir | ||
let filepath | ||
let ws | ||
|
||
if (!path) { | ||
throw new Error("Argument 'path' is required") | ||
} | ||
if (!options) { | ||
options = {} | ||
dir = process.cwd() | ||
} else { | ||
if (options.slice(-1) !== '/') { | ||
options += '/' | ||
} | ||
dir = options | ||
} | ||
|
||
utils.getIPFS((err, ipfs) => { | ||
if (err) { | ||
throw err | ||
} | ||
ipfs.files.get(path, (err, data) => { | ||
if (err) { | ||
throw err | ||
} | ||
data.on('file', (data) => { | ||
if (data.path.lastIndexOf('/') === -1) { | ||
filepath = data.path | ||
if (data.dir === false) { | ||
ws = fs.createWriteStream(pathj.join(dir, data.path)) | ||
data.stream.pipe(ws) | ||
} else { | ||
try { | ||
fs.mkdirSync(pathj.join(dir, data.path)) | ||
} catch (err) { | ||
throw err | ||
} | ||
} | ||
} else { | ||
filepath = data.path.substring(0, data.path.lastIndexOf('/') + 1) | ||
try { | ||
fs.mkdirSync(pathj.join(dir, filepath)) | ||
} catch (err) { | ||
throw err | ||
} | ||
ws = fs.createWriteStream(pathj.join(dir, data.path)) | ||
data.stream.pipe(ws) | ||
} | ||
}) | ||
}) | ||
}) | ||
} | ||
}) |
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.