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

Commit

Permalink
docs: document --parents flag for files.write command (#349)
Browse files Browse the repository at this point in the history
Also adds a test.

Already supported in `js-ipfs`, `go-ipfs` requires ipfs/kubo#5359
to be merged and released
  • Loading branch information
achingbrain authored and alanshaw committed Aug 28, 2018
1 parent 776dc09 commit e5f5b59
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions SPEC/FILES.md
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,7 @@ Where:
- `offset` is an Integer with the byte offset to begin writing at (default: 0)
- `create` is a Boolean to indicate to create the file if it doesn't exist (default: false)
- `truncate` is a Boolean to indicate if the file should be truncated after writing all the bytes from `content` (default: false)
- `parents` is a Boolean value to decide whether or not to make the parent directories if they don't exist (default: false)
- `length` is an Integer with the maximum number of bytes to read (default: Read all bytes from `content`)
- `raw-leaves`: if true, DAG leaves will contain raw file data and not be wrapped in a protobuf (boolean, default false)
- `cid-version`: the CID version to use when storing the data (storage keys are based on the CID, including it's version) (integer, default 0)
Expand Down
27 changes: 23 additions & 4 deletions js/src/files/write.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,31 @@ module.exports = (createCommon, options) => {
})
})

it('should write to non existent file with create flag, expect no error', function (done) {
const testDir = `/test-${hat()}`
it('should write to non existent file with create flag', function (done) {
const testPath = `/test-${hat()}`

ipfs.files.write(testDir, Buffer.from('Hello, world!'), {create: true}, (err) => {
ipfs.files.write(testPath, Buffer.from('Hello, world!'), {create: true}, (err) => {
expect(err).to.not.exist()
done()

ipfs.files.stat(testPath, (err, stats) => {
expect(err).to.not.exist()
expect(stats.type).to.equal('file')
done()
})
})
})

it('should write to deeply nested non existent file with create and parents flags', function (done) {
const testPath = `/foo/bar/baz/test-${hat()}`

ipfs.files.write(testPath, Buffer.from('Hello, world!'), {create: true, parents: true}, (err) => {
expect(err).to.not.exist()

ipfs.files.stat(testPath, (err, stats) => {
expect(err).to.not.exist()
expect(stats.type).to.equal('file')
done()
})
})
})
})
Expand Down

0 comments on commit e5f5b59

Please sign in to comment.