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

feat: add wrapWithDirectory to files.add et al #251

Merged
merged 1 commit into from
Apr 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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