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

Commit e5f5b59

Browse files
achingbrainalanshaw
authored andcommitted
docs: document --parents flag for files.write command (#349)
Also adds a test. Already supported in `js-ipfs`, `go-ipfs` requires ipfs/kubo#5359 to be merged and released
1 parent 776dc09 commit e5f5b59

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

SPEC/FILES.md

+1
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,7 @@ Where:
880880
- `offset` is an Integer with the byte offset to begin writing at (default: 0)
881881
- `create` is a Boolean to indicate to create the file if it doesn't exist (default: false)
882882
- `truncate` is a Boolean to indicate if the file should be truncated after writing all the bytes from `content` (default: false)
883+
- `parents` is a Boolean value to decide whether or not to make the parent directories if they don't exist (default: false)
883884
- `length` is an Integer with the maximum number of bytes to read (default: Read all bytes from `content`)
884885
- `raw-leaves`: if true, DAG leaves will contain raw file data and not be wrapped in a protobuf (boolean, default false)
885886
- `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)

js/src/files/write.js

+23-4
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,31 @@ module.exports = (createCommon, options) => {
4040
})
4141
})
4242

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

46-
ipfs.files.write(testDir, Buffer.from('Hello, world!'), {create: true}, (err) => {
46+
ipfs.files.write(testPath, Buffer.from('Hello, world!'), {create: true}, (err) => {
4747
expect(err).to.not.exist()
48-
done()
48+
49+
ipfs.files.stat(testPath, (err, stats) => {
50+
expect(err).to.not.exist()
51+
expect(stats.type).to.equal('file')
52+
done()
53+
})
54+
})
55+
})
56+
57+
it('should write to deeply nested non existent file with create and parents flags', function (done) {
58+
const testPath = `/foo/bar/baz/test-${hat()}`
59+
60+
ipfs.files.write(testPath, Buffer.from('Hello, world!'), {create: true, parents: true}, (err) => {
61+
expect(err).to.not.exist()
62+
63+
ipfs.files.stat(testPath, (err, stats) => {
64+
expect(err).to.not.exist()
65+
expect(stats.type).to.equal('file')
66+
done()
67+
})
4968
})
5069
})
5170
})

0 commit comments

Comments
 (0)