Skip to content

Commit 8e00ac7

Browse files
committed
chore: fix linter errors
1 parent 004f5fa commit 8e00ac7

File tree

11 files changed

+37
-47
lines changed

11 files changed

+37
-47
lines changed

packages/ipfs-unixfs-exporter/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"crypto-browserify": "^3.12.0",
4242
"detect-node": "^2.0.4",
4343
"events": "^3.3.0",
44-
"ipfs-core-types": "^0.3.1",
44+
"ipfs-core-types": "next",
4545
"ipfs-unixfs-importer": "^7.0.1",
4646
"it-all": "^1.0.5",
4747
"it-buffer-stream": "^2.0.0",

packages/ipfs-unixfs-exporter/src/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ const toPathComponents = (path = '') => {
3030
*/
3131
const cidAndRest = (path) => {
3232
if (path instanceof Uint8Array) {
33-
console.log('vmx: index: path:', path)
3433
return {
3534
cid: CID.decode(path),
3635
toResolve: []

packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/file.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async function * emitBytes (blockService, node, start, end, streamPosition = 0,
6666
(end > childStart && end <= childEnd) || // child has end byte
6767
(start < childStart && end > childEnd)) { // child is between offset and end bytes
6868
const block = await blockService.get(childLink.Hash, {
69-
signal: options.signal,
69+
signal: options.signal
7070
})
7171
let child
7272
switch (childLink.Hash.code) {
@@ -75,18 +75,16 @@ async function * emitBytes (blockService, node, start, end, streamPosition = 0,
7575
break
7676
case mc.RAW:
7777
child = block.bytes
78-
break;
78+
break
7979
case mc.DAG_CBOR:
8080
// @ts-ignore - TODO vmx 2021-04-01: will work once js-dag-cbor has proper types
8181
child = await dagCbor.decode(block.bytes)
82-
break;
82+
break
8383
default:
8484
// TODO vmx 2021-03-05: fix this type issue properly
8585
// @ts-ignore
8686
throw Error(`Unsupported codec: ${mc.getName(childLink.Hash.code)}`)
8787
}
88-
//console.log('file: childlink cid codec:', childLink.Hash.code)
89-
//const child = await decode(block.bytes)
9088

9189
for await (const buf of emitBytes(blockService, child, start, end, streamPosition, options)) {
9290
streamPosition += buf.length

packages/ipfs-unixfs-exporter/test/exporter.spec.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ describe('exporter', () => {
269269
data: content.slice(0, 5)
270270
})
271271
const chunkNode1 = dagPb.prepare({ Data: chunk1.marshal() })
272-
// TODO vmx 2022-02-23: Use CIv0
273272
const chunkBlock1 = await Block.encode({
274273
value: chunkNode1,
275274
codec: dagPb,
@@ -283,7 +282,6 @@ describe('exporter', () => {
283282
codec: dagPb,
284283
hasher: sha256
285284
})
286-
// TODO vmx 2022-02-23: USE CIDv0
287285
const chunkBlock2 = await Block.encode({
288286
value: chunkNode2,
289287
codec: dagPb,
@@ -302,22 +300,21 @@ describe('exporter', () => {
302300
Links: [{
303301
Name: '',
304302
Tsize: chunkNode1.size,
305-
Hash: chunkBlock1.cid
303+
Hash: chunkBlock1.cid.toV0()
306304
}, {
307305
Name: '',
308306
Tsize: chunkNode2.size,
309-
Hash: chunkBlock2.cid
307+
Hash: chunkBlock2.cid.toV0()
310308
}]
311309
})
312-
// TODO vmx 2022-02-23: Use CIDv0
313310
const fileBlock = await Block.encode({
314311
value: fileNode,
315312
codec: dagPb,
316313
hasher: sha256
317314
})
318315
await block.put(fileBlock)
319316

320-
const exported = await exporter(fileBlock.cid, block)
317+
const exported = await exporter(fileBlock.cid.toV0(), block)
321318

322319
if (exported.type !== 'file') {
323320
throw new Error('Unexpected type')

packages/ipfs-unixfs-exporter/test/helpers/block.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict'
22

3+
const errCode = require('err-code')
4+
35
function createBlockApi () {
46
/** @type {{[key: string]: Uint8Array}} */
57
const blocks = {}
@@ -16,10 +18,7 @@ function createBlockApi () {
1618
get: async (cid, _options) => {
1719
const bytes = blocks[cid.toV1().toString()]
1820
if (bytes === undefined) {
19-
const error = new Error(`Couold not find data for CID '${cid}'`)
20-
// @ts-ignore - TODO vmx 2021-03-24: Should the error type be wrapped in a custom type?
21-
error.code = 'ERR_NOT_FOUND'
22-
throw(error)
21+
throw errCode(new Error(`Couold not find data for CID '${cid}'`), 'ERR_NOT_FOUND')
2322
}
2423

2524
return { cid, bytes }

packages/ipfs-unixfs-exporter/test/importer.spec.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ const { decode } = require('@ipld/dag-pb')
3030
const { parseMtime } = require('ipfs-unixfs')
3131

3232
/**
33-
* @typedef {import('ipfs-core-types/src/block-service').BlockService} BlockService
3433
* @typedef {import('ipfs-unixfs-importer/src/types').BlockAPI} BlockAPI
3534
* @typedef {import('../src/types').PbNode} PbNode
3635
*/
@@ -226,7 +225,7 @@ const checkLeafNodeTypes = async (block, options, expected) => {
226225
node.Links.map(link => block.get(link.Hash))
227226
)
228227

229-
linkedBlocks.forEach(({ bytes}) => {
228+
linkedBlocks.forEach(({ bytes }) => {
230229
const node = decode(bytes)
231230
const meta = UnixFS.unmarshal(node.Data)
232231
expect(meta.type).to.equal(expected)

packages/ipfs-unixfs-importer/src/dag-builder/file/index.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const {
1010
} = require('@ipld/dag-pb')
1111
const parallelBatch = require('it-parallel-batch')
1212
const mc = require('multicodec')
13-
//const mh = require('multiformats/hashes/digest')
13+
// const mh = require('multiformats/hashes/digest')
1414
const rawCodec = require('multiformats/codecs/raw')
1515

1616
/**
@@ -94,25 +94,25 @@ const reduce = (file, block, options) => {
9494

9595
buffer = encode(prepare({ Data: leaf.unixfs.marshal() }))
9696

97-
//// TODO vmx 2021-03-26: This is what the original code does, it checks
98-
//// the multihash of the original leaf node and uses then the same
99-
//// hasher. i wonder if that's really needed or if we could just use
100-
//// the hasher from `options.hasher` instead.
101-
//const multihash = mh.decode(leaf.cid.multihash.bytes)
102-
//let hasher
103-
//switch multihash {
104-
// case sha256.code {
105-
// hasher = sha256
106-
// break;
107-
// }
108-
// //case identity.code {
109-
// // hasher = identity
110-
// // break;
111-
// //}
112-
// default: {
113-
// throw new Error(`Unsupported hasher "${multihash}"`)
114-
// }
115-
//}
97+
// // TODO vmx 2021-03-26: This is what the original code does, it checks
98+
// // the multihash of the original leaf node and uses then the same
99+
// // hasher. i wonder if that's really needed or if we could just use
100+
// // the hasher from `options.hasher` instead.
101+
// const multihash = mh.decode(leaf.cid.multihash.bytes)
102+
// let hasher
103+
// switch multihash {
104+
// case sha256.code {
105+
// hasher = sha256
106+
// break;
107+
// }
108+
// //case identity.code {
109+
// // hasher = identity
110+
// // break;
111+
// //}
112+
// default: {
113+
// throw new Error(`Unsupported hasher "${multihash}"`)
114+
// }
115+
// }
116116
leaf.cid = await persist(buffer, block, {
117117
...options,
118118
codec: mc.DAG_PB,

packages/ipfs-unixfs-importer/src/utils/persist.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const { CID } = require('multiformats/cid')
1010
*/
1111
const persist = async (buffer, block, options) => {
1212
if (!options.hasher) {
13-
throw new Error(`Hasher must be specified.`)
13+
throw new Error('Hasher must be specified.')
1414
}
1515

1616
if (!options.codec) {
@@ -32,7 +32,7 @@ const persist = async (buffer, block, options) => {
3232
// @ts-ignore pin option is missing from block api typedefs
3333
pin: options.pin,
3434
preload: options.preload,
35-
timeout: options.timeout,
35+
timeout: options.timeout
3636
})
3737
}
3838

packages/ipfs-unixfs-importer/test/builder.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,4 @@ describe('builder', () => {
109109
expect(meta.type).to.equal('directory')
110110
}
111111
})
112-
})
112+
})

packages/ipfs-unixfs-importer/test/chunker-custom.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const blockApi = require('./helpers/block')
1111
const uint8ArrayFromString = require('uint8arrays/from-string')
1212
const { UnixFS } = require('ipfs-unixfs')
1313

14-
1514
const iter = async function * () {
1615
yield uint8ArrayFromString('one')
1716
yield uint8ArrayFromString('two')

packages/ipfs-unixfs-importer/test/helpers/block.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict'
22

3+
const errCode = require('err-code')
4+
35
function createBlockApi () {
46
/** @type {{[key: string]: Uint8Array}} */
57
const blocks = {}
@@ -16,10 +18,7 @@ function createBlockApi () {
1618
get: async (cid, _options) => {
1719
const bytes = blocks[cid.toV1().toString()]
1820
if (bytes === undefined) {
19-
const error = new Error(`Couold not find data for CID '${cid}'`)
20-
// @ts-ignore - TODO vmx 2021-03-24: Should the error type be wrapped in a custom type?
21-
error.code = 'ERR_NOT_FOUND'
22-
throw(error)
21+
throw errCode(new Error(`Couold not find data for CID '${cid}'`), 'ERR_NOT_FOUND')
2322
}
2423

2524
return { cid, bytes }

0 commit comments

Comments
 (0)