Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 7b92684

Browse files
committed
feat: support --raw-leaves
1 parent f4344b0 commit 7b92684

File tree

4 files changed

+27
-87
lines changed

4 files changed

+27
-87
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@
108108
"ipfs-block": "~0.7.1",
109109
"ipfs-block-service": "~0.14.0",
110110
"ipfs-http-response": "~0.1.2",
111-
"ipfs-mfs": "~0.1.0",
111+
"ipfs-mfs": "~0.2.2",
112112
"ipfs-multipart": "~0.1.0",
113113
"ipfs-repo": "~0.22.1",
114114
"ipfs-unixfs": "~0.1.15",
115-
"ipfs-unixfs-engine": "~0.30.0",
115+
"ipfs-unixfs-engine": "~0.31.2",
116116
"ipld": "~0.17.3",
117117
"ipld-dag-cbor": "~0.12.1",
118118
"ipld-dag-pb": "~0.14.5",

src/cli/commands/files/add.js

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -145,17 +145,19 @@ module.exports = {
145145
},
146146
'raw-leaves': {
147147
type: 'boolean',
148-
default: undefined,
148+
default: false,
149149
describe: 'Use raw blocks for leaf nodes. (experimental)'
150150
},
151151
'cid-version': {
152152
type: 'integer',
153-
describe: 'Cid version. Non-zero value will change default of \'raw-leaves\' to true. (experimental)'
153+
describe: 'CID version. Defaults to 0 unless an option that depends on CIDv1 is passed. (experimental)',
154+
default: 0
154155
},
155156
hash: {
156157
type: 'string',
157158
choices: Object.keys(mh.names),
158-
describe: 'Hash function to use. Will set Cid version to 1 if used. (experimental)'
159+
describe: 'Hash function to use. Will set Cid version to 1 if used. (experimental)',
160+
default: 'sha2-256'
159161
},
160162
quiet: {
161163
alias: 'q',
@@ -197,34 +199,6 @@ module.exports = {
197199
pin: argv.pin
198200
}
199201

200-
// Temporary restriction on raw-leaves:
201-
// When cid-version=1 then raw-leaves MUST be present and false.
202-
//
203-
// This is because raw-leaves is not yet implemented in js-ipfs,
204-
// and go-ipfs changes the value of raw-leaves to true when
205-
// cid-version > 0 unless explicitly set to false.
206-
//
207-
// This retains feature parity without having to implement raw-leaves.
208-
if (options.cidVersion > 0 && options.rawLeaves !== false) {
209-
throw new Error('Implied argument raw-leaves must be passed and set to false when cid-version is > 0')
210-
}
211-
212-
// Temporary restriction on raw-leaves:
213-
// When hash != undefined then raw-leaves MUST be present and false.
214-
//
215-
// This is because raw-leaves is not yet implemented in js-ipfs,
216-
// and go-ipfs changes the value of raw-leaves to true when
217-
// hash != undefined unless explicitly set to false.
218-
//
219-
// This retains feature parity without having to implement raw-leaves.
220-
if (options.hash && options.rawLeaves !== false) {
221-
throw new Error('Implied argument raw-leaves must be passed and set to false when hash argument is specified')
222-
}
223-
224-
if (options.rawLeaves) {
225-
throw new Error('Not implemented: raw-leaves')
226-
}
227-
228202
if (options.enableShardingExperiment && utils.isDaemonOn()) {
229203
throw new Error('Error: Enabling the sharding experiment should be done on the daemon')
230204
}

src/http/api/resources/files.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,20 +153,8 @@ exports.add = {
153153
validate: {
154154
query: Joi.object()
155155
.keys({
156-
'cid-version': Joi.number().integer().min(0).max(1),
157-
// Temporary restriction on raw-leaves:
158-
// When cid-version=1 then raw-leaves MUST be present and false.
159-
//
160-
// This is because raw-leaves is not yet implemented in js-ipfs,
161-
// and go-ipfs changes the value of raw-leaves to true when
162-
// cid-version > 0 unless explicitly set to false.
163-
//
164-
// This retains feature parity without having to implement raw-leaves.
165-
'raw-leaves': Joi.boolean().when('cid-version', {
166-
is: 1,
167-
then: Joi.boolean().valid(false).required(),
168-
otherwise: Joi.boolean().valid(false)
169-
}),
156+
'cid-version': Joi.number().integer().min(0).max(1).default(0),
157+
'raw-leaves': Joi.boolean(),
170158
'only-hash': Joi.boolean(),
171159
pin: Joi.boolean().default(true),
172160
'wrap-with-directory': Joi.boolean()

test/cli/files.js

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -205,56 +205,34 @@ describe('files', () => runOnAndOff((thing) => {
205205
})
206206
})
207207

208-
// Temporarily expect to fail as raw-leaves not yet implemented.
209-
//
210-
// When cid-version=1 then raw-leaves MUST be present and false.
211-
//
212-
// This is because raw-leaves is not yet implemented in js-ipfs,
213-
// and go-ipfs changes the value of raw-leaves to true when
214-
// cid-version > 0 unless explicitly set to false.
215-
//
216-
// This retains feature parity without having to implement raw-leaves.
217208
it('add with cid-version=1', function () {
218209
this.timeout(30 * 1000)
219210

220-
return new Promise((resolve, reject) => {
221-
ipfs('add src/init-files/init-docs/readme --cid-version=1')
222-
.then(() => reject(new Error('Raw leaves not expected to be implemented')))
223-
.catch((err) => {
224-
expect(err).to.exist()
225-
resolve()
226-
})
227-
})
211+
return ipfs('add src/init-files/init-docs/readme --cid-version=1')
212+
.then((out) => {
213+
expect(out)
214+
.to.eql('added zdj7WWeQ43G6JJvLWQWZpyHuAMq6uYWRjkBXFad11vE2LHhQ7 readme\n')
215+
})
228216
})
229217

230-
// TODO: this test is failing, @alanshaw?
231-
it.skip('add with cid-version=1 and raw-leaves=false', () => {
232-
return ipfs('add src/init-files/init-docs/readme --cid-version=1 --raw-leaves=false').then((out) => {
233-
expect(out)
234-
.to.eql('added zdj7WWeQ43G6JJvLWQWZpyHuAMq6uYWRjkBXFad11vE2LHhQ7 readme\n')
235-
})
218+
it('add with cid-version=1 and raw-leaves=false', () => {
219+
this.timeout(30 * 1000)
220+
221+
return ipfs('add src/init-files/init-docs/readme --cid-version=1 --raw-leaves=false')
222+
.then((out) => {
223+
expect(out)
224+
.to.eql('added zdj7WWeQ43G6JJvLWQWZpyHuAMq6uYWRjkBXFad11vE2LHhQ7 readme\n')
225+
})
236226
})
237227

238-
// Temporarily expect to fail as raw-leaves not yet implemented
239-
//
240-
// When cid-version=1 then raw-leaves MUST be present and false.
241-
//
242-
// This is because raw-leaves is not yet implemented in js-ipfs,
243-
// and go-ipfs changes the value of raw-leaves to true when
244-
// cid-version > 0 unless explicitly set to false.
245-
//
246-
// This retains feature parity without having to implement raw-leaves.
247228
it('add with cid-version=1 and raw-leaves=true', function () {
248229
this.timeout(30 * 1000)
249230

250-
return new Promise((resolve, reject) => {
251-
ipfs('add src/init-files/init-docs/readme --cid-version=1 --raw-leaves=true')
252-
.then(() => reject(new Error('Raw leaves not expected to be implemented')))
253-
.catch((err) => {
254-
expect(err).to.exist()
255-
resolve()
256-
})
257-
})
231+
return ipfs('add src/init-files/init-docs/readme --cid-version=1 --raw-leaves=true')
232+
.then((out) => {
233+
expect(out)
234+
.to.eql('added zdj7WiLc855B1KPRgV7Fh8ivjuAhePE1tuJafmxH5HmmSjqaD readme\n')
235+
})
258236
})
259237

260238
it('add --quiet', function () {

0 commit comments

Comments
 (0)