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.
Merge pull request #306 from ipfs/update/files-add-interface
update/files add interface
- Loading branch information
Showing
13 changed files
with
119 additions
and
94 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
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
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,64 +1,19 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const bl = require('bl') | ||
const expect = require('chai').expect | ||
const Readable = require('stream').Readable | ||
const bs58 = require('bs58') | ||
|
||
const test = require('interface-ipfs-core') | ||
const IPFS = require('../../../src/core') | ||
|
||
describe('files', () => { | ||
let ipfs | ||
|
||
before((done) => { | ||
ipfs = new IPFS(require('../../utils/repo-path')) | ||
ipfs.load(done) | ||
}) | ||
|
||
it('add', (done) => { | ||
const buffered = new Buffer('some data') | ||
const rs = new Readable() | ||
rs.push(buffered) | ||
rs.push(null) | ||
const arr = [] | ||
const filePair = {path: 'data.txt', stream: rs} | ||
arr.push(filePair) | ||
ipfs.files.add(arr, (err, res) => { | ||
expect(err).to.not.exist | ||
expect(res[0].path).to.equal('data.txt') | ||
expect(res[0].size).to.equal(17) | ||
expect(bs58.encode(res[0].multihash).toString()).to.equal('QmVv4Wz46JaZJeH5PMV4LGbRiiMKEmszPYY3g6fjGnVXBS') | ||
done() | ||
const common = { | ||
setup: function (cb) { | ||
const ipfs = new IPFS(require('../../utils/repo-path')) | ||
ipfs.load(() => { | ||
cb(null, ipfs) | ||
}) | ||
}) | ||
}, | ||
teardown: function (cb) { | ||
cb() | ||
} | ||
} | ||
|
||
it('cat', (done) => { | ||
const hash = 'QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o' | ||
ipfs.files.cat(hash, (err, res) => { | ||
expect(err).to.not.exist | ||
res.on('data', (data) => { | ||
data.stream.pipe(bl((err, bldata) => { | ||
expect(err).to.not.exist | ||
expect(bldata.toString()).to.equal('hello world\n') | ||
done() | ||
})) | ||
}) | ||
}) | ||
}) | ||
|
||
it('get', (done) => { | ||
// TODO create non-trival get test | ||
const hash = 'QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o' | ||
ipfs.files.get(hash, (err, res) => { | ||
expect(err).to.not.exist | ||
res.on('data', (data) => { | ||
data.stream.pipe(bl((err, bldata) => { | ||
expect(err).to.not.exist | ||
expect(bldata.toString()).to.equal('hello world\n') | ||
done() | ||
})) | ||
}) | ||
}) | ||
}) | ||
}) | ||
test.files(common) |
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
What happens if there is an error (sync or async) and
counter
doesn't get decremented, hence never becomes zero? DoescanFinish
get repeated forever?