Skip to content

Commit

Permalink
fix: update unixfs importer
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Feb 17, 2023
1 parent d893bc2 commit f6edeca
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"interface-blockstore": "^4.0.1",
"ipfs-unixfs": "^11.0.0",
"ipfs-unixfs-exporter": "^12.0.0",
"ipfs-unixfs-importer": "^14.0.0",
"ipfs-unixfs-importer": "^14.0.1",
"it-last": "^2.0.0",
"it-pipe": "^2.0.5",
"merge-options": "^3.0.4",
Expand Down
4 changes: 1 addition & 3 deletions src/commands/chmod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ export async function chmod (cid: CID, mode: number, blockstore: Blockstore, opt
}
}
},
// @ts-expect-error we account for the incompatible source type with our custom dag builder below
(source) => importer(source, blockstore, {
...opts,
pin: false,
dagBuilder: async function * (source, block) {
for await (const entry of source) {
yield async function () {
Expand All @@ -87,7 +85,7 @@ export async function chmod (cid: CID, mode: number, blockstore: Blockstore, opt

return {
cid: updatedCid,
size: buf.length,
size: BigInt(buf.length),
path: entry.path,
unixfs
}
Expand Down
4 changes: 1 addition & 3 deletions src/commands/touch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@ export async function touch (cid: CID, blockstore: Blockstore, options: Partial<
}
}
},
// @ts-expect-error we account for the incompatible source type with our custom dag builder below
(source) => importer(source, blockstore, {
...opts,
pin: false,
dagBuilder: async function * (source, block) {
for await (const entry of source) {
yield async function () {
Expand All @@ -91,7 +89,7 @@ export async function touch (cid: CID, blockstore: Blockstore, options: Partial<

return {
cid: updatedCid,
size: buf.length,
size: BigInt(buf.length),
path: entry.path,
unixfs
}
Expand Down
4 changes: 2 additions & 2 deletions test/cat.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { unixfs, UnixFS } from '../src/index.js'
import { MemoryBlockstore } from 'blockstore-core'
import toBuffer from 'it-to-buffer'
import drain from 'it-drain'
import { importContent, importBytes } from 'ipfs-unixfs-importer'
import { importDirectory, importBytes } from 'ipfs-unixfs-importer'
import { createShardedDirectory } from './fixtures/create-sharded-directory.js'

const smallFile = Uint8Array.from(new Array(13).fill(0).map(() => Math.random() * 100))
Expand All @@ -22,7 +22,7 @@ describe('cat', () => {

fs = unixfs({ blockstore })

const imported = await importContent({ path: 'empty' }, blockstore)
const imported = await importDirectory({ path: 'empty' }, blockstore)
emptyDirCid = imported.cid
})

Expand Down
4 changes: 2 additions & 2 deletions test/chmod.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Blockstore } from 'interface-blockstore'
import { MemoryBlockstore } from 'blockstore-core'
import { UnixFS, unixfs } from '../src/index.js'
import type { CID } from 'multiformats/cid'
import { importContent, importBytes } from 'ipfs-unixfs-importer'
import { importDirectory, importBytes } from 'ipfs-unixfs-importer'
import { createShardedDirectory } from './fixtures/create-sharded-directory.js'

const smallFile = Uint8Array.from(new Array(13).fill(0).map(() => Math.random() * 100))
Expand All @@ -20,7 +20,7 @@ describe('chmod', () => {

fs = unixfs({ blockstore })

const imported = await importContent({ path: 'empty' }, blockstore)
const imported = await importDirectory({ path: 'empty' }, blockstore)
emptyDirCid = imported.cid
})

Expand Down
4 changes: 2 additions & 2 deletions test/cp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { Blockstore } from 'interface-blockstore'
import { unixfs, UnixFS } from '../src/index.js'
import { MemoryBlockstore } from 'blockstore-core'
import toBuffer from 'it-to-buffer'
import { importContent, importBytes } from 'ipfs-unixfs-importer'
import { importDirectory, importBytes } from 'ipfs-unixfs-importer'
import { createShardedDirectory } from './fixtures/create-sharded-directory.js'
import first from 'it-first'

Expand All @@ -22,7 +22,7 @@ describe('cp', () => {

fs = unixfs({ blockstore })

const imported = await importContent({ path: 'empty' }, blockstore)
const imported = await importDirectory({ path: 'empty' }, blockstore)
emptyDirCid = imported.cid
})

Expand Down
4 changes: 2 additions & 2 deletions test/ls.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import all from 'it-all'
import type { Blockstore } from 'interface-blockstore'
import { unixfs, UnixFS } from '../src/index.js'
import { MemoryBlockstore } from 'blockstore-core'
import { importContent, importBytes } from 'ipfs-unixfs-importer'
import { importDirectory, importBytes } from 'ipfs-unixfs-importer'
import { createShardedDirectory } from './fixtures/create-sharded-directory.js'

describe('ls', () => {
Expand All @@ -19,7 +19,7 @@ describe('ls', () => {

fs = unixfs({ blockstore })

const imported = await importContent({ path: 'empty' }, blockstore)
const imported = await importDirectory({ path: 'empty' }, blockstore)
emptyDirCid = imported.cid
})

Expand Down
6 changes: 3 additions & 3 deletions test/mkdir.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { unixfs, UnixFS } from '../src/index.js'
import { MemoryBlockstore } from 'blockstore-core'
import type { CID } from 'multiformats/cid'
import type { Mtime } from 'ipfs-unixfs'
import { importContent } from 'ipfs-unixfs-importer'
import { importDirectory } from 'ipfs-unixfs-importer'
import { createShardedDirectory } from './fixtures/create-sharded-directory.js'

describe('mkdir', () => {
Expand All @@ -21,10 +21,10 @@ describe('mkdir', () => {

fs = unixfs({ blockstore })

const imported = await importContent({ path: 'empty' }, blockstore)
const imported = await importDirectory({ path: 'empty' }, blockstore)
emptyDirCid = imported.cid

const importedV0 = await importContent({ path: 'empty' }, blockstore, {
const importedV0 = await importDirectory({ path: 'empty' }, blockstore, {
cidVersion: 0
})
emptyDirCidV0 = importedV0.cid
Expand Down
4 changes: 2 additions & 2 deletions test/rm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Blockstore } from 'interface-blockstore'
import { unixfs, UnixFS } from '../src/index.js'
import { MemoryBlockstore } from 'blockstore-core'
import type { CID } from 'multiformats/cid'
import { importContent, importBytes, importer } from 'ipfs-unixfs-importer'
import { importDirectory, importBytes, importer } from 'ipfs-unixfs-importer'
import { createShardedDirectory } from './fixtures/create-sharded-directory.js'
import last from 'it-last'
import { createSubshardedDirectory } from './fixtures/create-subsharded-directory.js'
Expand All @@ -22,7 +22,7 @@ describe('rm', () => {

fs = unixfs({ blockstore })

const imported = await importContent({ path: 'empty' }, blockstore)
const imported = await importDirectory({ path: 'empty' }, blockstore)
emptyDirCid = imported.cid
})

Expand Down
8 changes: 4 additions & 4 deletions test/stat.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { unixfs, UnixFS } from '../src/index.js'
import { MemoryBlockstore } from 'blockstore-core'
import type { CID } from 'multiformats/cid'
import * as dagPb from '@ipld/dag-pb'
import { importContent, importBytes } from 'ipfs-unixfs-importer'
import { importDirectory, importBytes, importFile } from 'ipfs-unixfs-importer'
import { createShardedDirectory } from './fixtures/create-sharded-directory.js'

const smallFile = Uint8Array.from(new Array(13).fill(0).map(() => Math.random() * 100))
Expand All @@ -24,7 +24,7 @@ describe('stat', function () {

fs = unixfs({ blockstore })

const imported = await importContent({ path: 'empty' }, blockstore)
const imported = await importDirectory({ path: 'empty' }, blockstore)
emptyDirCid = imported.cid
})

Expand Down Expand Up @@ -100,7 +100,7 @@ describe('stat', function () {

it('should stat file with mode', async () => {
const mode = 0o644
const { cid } = await importContent({
const { cid } = await importFile({
content: smallFile,
mode
}, blockstore)
Expand All @@ -115,7 +115,7 @@ describe('stat', function () {
secs: 5n,
nsecs: 0
}
const { cid } = await importContent({
const { cid } = await importFile({
content: smallFile,
mtime
}, blockstore)
Expand Down
6 changes: 3 additions & 3 deletions test/touch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { unixfs, UnixFS } from '../src/index.js'
import { MemoryBlockstore } from 'blockstore-core'
import type { CID } from 'multiformats/cid'
import delay from 'delay'
import { importContent, importBytes } from 'ipfs-unixfs-importer'
import { importDirectory, importBytes, importFile } from 'ipfs-unixfs-importer'
import { createShardedDirectory } from './fixtures/create-sharded-directory.js'

describe('.files.touch', () => {
Expand All @@ -19,7 +19,7 @@ describe('.files.touch', () => {

fs = unixfs({ blockstore })

const imported = await importContent({ path: 'empty' }, blockstore)
const imported = await importDirectory({ path: 'empty' }, blockstore)
emptyDirCid = imported.cid
})

Expand All @@ -43,7 +43,7 @@ describe('.files.touch', () => {
const mtime = new Date()
const seconds = BigInt(Math.floor(mtime.getTime() / 1000))

const { cid } = await importContent({
const { cid } = await importFile({
content: Uint8Array.from([0, 1, 2, 3, 4]),
mtime: {
secs: seconds
Expand Down

0 comments on commit f6edeca

Please sign in to comment.