This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #337 from ipfs/feat/ipfs.files.get
feat/ipfs.files.get
- Loading branch information
Showing
16 changed files
with
260 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
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 tarStreamToObjects = require('../tar-stream-to-objects') | ||
const cleanMultihash = require('../clean-multihash') | ||
const promisify = require('promisify-es6') | ||
|
||
module.exports = (send) => { | ||
return promisify(function get (path, opts, cb) { | ||
if (typeof opts === 'function' && !cb) { | ||
cb = opts | ||
opts = {} | ||
} | ||
|
||
// opts is the real callback -- 'cb' is being injected by promisify | ||
if (typeof opts === 'function' && typeof cb === 'function') { | ||
cb = opts | ||
opts = {} | ||
} | ||
|
||
try { | ||
path = cleanMultihash(path) | ||
} catch (err) { | ||
return cb(err) | ||
} | ||
|
||
var sendWithTransform = send.withTransform(tarStreamToObjects) | ||
|
||
return sendWithTransform('get', path, opts, null, cb) | ||
}) | ||
} |
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,15 @@ | ||
'use strict' | ||
|
||
const bs58 = require('bs58') | ||
const isIPFS = require('is-ipfs') | ||
|
||
module.exports = function (multihash) { | ||
if (!isIPFS.multihash(multihash)) { | ||
throw new Error('not valid multihash') | ||
} | ||
if (Buffer.isBuffer(multihash)) { | ||
return bs58.encode(multihash) | ||
} | ||
return multihash | ||
} | ||
|
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,32 @@ | ||
'use strict' | ||
|
||
const tar = require('tar-stream') | ||
const Readable = require('readable-stream') | ||
|
||
// transform tar stream into readable stream of | ||
// { path: 'string', content: Readable } | ||
module.exports = function (err, res, send, done) { | ||
if (err) { | ||
return done(err) | ||
} | ||
|
||
var ex = tar.extract() | ||
res.pipe(ex) | ||
|
||
var objStream = new Readable({ objectMode: true }) | ||
objStream._read = function noop () {} | ||
|
||
ex.on('entry', function (header, stream, next) { | ||
objStream.push({ | ||
path: header.name, | ||
content: header.type !== 'directory' ? stream : null | ||
}) | ||
next() | ||
}) | ||
ex.on('finish', () => { | ||
objStream.push(null) | ||
}) | ||
|
||
done(null, objStream) | ||
} | ||
|
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,4 +1,5 @@ | ||
/* eslint-env mocha */ | ||
/* eslint max-nested-callbacks: ["error", 8] */ | ||
/* globals apiClients */ | ||
'use strict' | ||
|
||
|
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,4 +1,5 @@ | ||
/* eslint-env mocha */ | ||
/* eslint max-nested-callbacks: ["error", 8] */ | ||
/* globals apiClients */ | ||
'use strict' | ||
|
||
|
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,4 +1,5 @@ | ||
/* eslint-env mocha */ | ||
/* eslint max-nested-callbacks: ["error", 8] */ | ||
/* globals apiClients */ | ||
'use strict' | ||
|
||
|
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,4 +1,5 @@ | ||
/* eslint-env mocha */ | ||
/* eslint max-nested-callbacks: ["error", 8] */ | ||
/* globals apiClients */ | ||
'use strict' | ||
|
||
|
Oops, something went wrong.