Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
feat: add wrapWithDirectory to files.add et al
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar authored and daviddias committed Apr 3, 2018
1 parent 4536160 commit 03eec9e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions SPEC/FILES.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ If no `content` is passed, then the path is treated as an empty directory
- progress (function): a function that will be called with the byte length of chunks as a file is added to ipfs.
- recursive (boolean): for when a Path is passed, this option can be enabled to add recursively all the files.
- hashAlg || hash (string): multihash hashing algorithm to use
- wrapWithDirectory (boolean): adds a wrapping node around the content

`callback` must follow `function (err, res) {}` signature, where `err` is an error if the operation was not successful. `res` will be an array of:

Expand Down Expand Up @@ -83,6 +84,7 @@ Returns a Readable Stream of class Duplex, where objects can be written of the f
- cid-version (integer, default 0): the CID version to use when storing the data (storage keys are based on the CID, including it's version)
- progress (function): a function that will be called with the byte length of chunks as a file is added to ipfs.
- hashAlg || hash (string): multihash hashing algorithm to use
- wrapWithDirectory (boolean): adds a wrapping node around the content

**Example:**

Expand Down Expand Up @@ -131,6 +133,7 @@ Returns a Pull Stream, where objects can be written of the forms
- cid-version (integer, default 0): the CID version to use when storing the data (storage keys are based on the CID, including it's version)
- progress (function): a function that will be called with the byte length of chunks as a file is added to ipfs.
- hashAlg || hash (string): multihash hashing algorithm to use
- wrapWithDirectory (boolean): adds a wrapping node around the content

**Example:**

Expand Down
19 changes: 19 additions & 0 deletions js/src/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@ module.exports = (common) => {
return loadFixture(path, 'interface-ipfs-core')
}

const wrapDirectory = {
path: 'wrapper/',
cid: 'QmbzKtHxQXJnWG9VR66TscUfcoK3CV4nceRsCdyAEsEj9A'
}

const smallFile = {
cid: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP',
data: fixture('js/test/fixtures/testfile.txt')
}

const bigFile = {
cid: 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq',
data: fixture('js/test/fixtures/15mb.random')
Expand Down Expand Up @@ -257,6 +263,19 @@ module.exports = (common) => {
})
})

it('wrapWithDirectory', (done) => {
return ipfs.files.add({ path: 'testfile.txt', content: smallFile.data }, { wrapWithDirectory: true }, (err, filesAdded) => {
expect(err).to.not.exist();
expect(filesAdded).to.have.length(2);
const file = filesAdded[0];
const wrapped = filesAdded[1]
expect(file.hash).to.equal(smallFile.cid)
expect(file.path).to.equal('testfile.txt')
expect(wrapped.path).to.equal(wrapDirectory.cid);
done();
});
});

it('Promise test', () => {
return ipfs.files.add(smallFile.data)
.then((filesAdded) => {
Expand Down

0 comments on commit 03eec9e

Please sign in to comment.