Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: tighten up input types #133

Merged
merged 10 commits into from
Mar 19, 2021
Merged
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"description": "JS implementation of the IPFS UnixFS",
"scripts": {
"reset": "lerna run clean && rimraf packages/*/node_modules node_modules",
"reset": "lerna run clean && rimraf packages/*/node_modules node_modules packages/*/package-lock.json package-lock.json",
"test": "lerna run test",
"coverage": "lerna run coverage",
"prepare": "lerna run prepare",
Expand Down Expand Up @@ -51,6 +51,7 @@
"packages/*"
],
"engines": {
"node": ">=14.0.0",
"npm": ">=7.0.0"
}
}
6 changes: 3 additions & 3 deletions packages/ipfs-unixfs-exporter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
"url": "https://github.com/ipfs/js-ipfs-unixfs/issues"
},
"engines": {
"node": ">=10.0.0",
"npm": ">=4.0.0"
"node": ">=14.0.0",
"npm": ">=7.0.0"
},
"homepage": "https://github.com/ipfs/js-ipfs-unixfs#readme",
"devDependencies": {
"@types/mocha": "^8.2.1",
"@types/sinon": "^9.0.10",
"abort-controller": "^3.0.0",
"aegir": "^32.0.0",
"aegir": "^32.1.0",
"copy": "^0.3.2",
"crypto-browserify": "^3.12.0",
"detect-node": "^2.0.4",
Expand Down
7 changes: 4 additions & 3 deletions packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const {
} = require('ipld-dag-pb')
const blockApi = require('./helpers/block')
const uint8ArrayConcat = require('uint8arrays/concat')
const asAsyncIterable = require('./helpers/as-async-iterable')

/**
* @typedef {import('cids')} CID
Expand Down Expand Up @@ -49,14 +50,14 @@ describe('exporter sharded', function () {
const createShardWithFileNames = (numFiles, fileName) => {
const files = new Array(numFiles).fill(0).map((_, index) => ({
path: fileName(index),
content: Uint8Array.from([0, 1, 2, 3, 4, index])
content: asAsyncIterable(Uint8Array.from([0, 1, 2, 3, 4, index]))
}))

return createShardWithFiles(files)
}

/**
* @param {{ path: string, content: Uint8Array }[] } files
* @param {{ path: string, content: AsyncIterable<Uint8Array> }[] } files
*/
const createShardWithFiles = async (files) => {
const result = await last(importer(files, block, {
Expand Down Expand Up @@ -88,7 +89,7 @@ describe('exporter sharded', function () {

const imported = await all(importer(Object.keys(files).map(path => ({
path,
content: files[path].content
content: asAsyncIterable(files[path].content)
})), block, {
wrapWithDirectory: true,
shardSplitThreshold: SHARD_SPLIT_THRESHOLD
Expand Down
9 changes: 5 additions & 4 deletions packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const last = require('it-last')
const blockApi = require('./helpers/block')
const randomBytes = require('it-buffer-stream')
const uint8ArrayConcat = require('uint8arrays/concat')
const asAsyncIterable = require('./helpers/as-async-iterable')

const ONE_MEG = Math.pow(1024, 2)

Expand All @@ -36,7 +37,7 @@ describe('exporter subtree', () => {
content: randomBytes(ONE_MEG)
}, {
path: './level-1/200Bytes.txt',
content
content: asAsyncIterable(content)
}], block))

if (!imported) {
Expand Down Expand Up @@ -64,7 +65,7 @@ describe('exporter subtree', () => {
content: randomBytes(ONE_MEG)
}, {
path: './level-1/200Bytes.txt',
content
content: asAsyncIterable(content)
}, {
path: './level-1/level-2'
}], block))
Expand Down Expand Up @@ -121,12 +122,12 @@ describe('exporter subtree', () => {
content: randomBytes(ONE_MEG)
}, {
path: './level-1/200Bytes.txt',
content
content: asAsyncIterable(content)
}, {
path: './level-1/level-2'
}, {
path: './level-1/level-2/200Bytes.txt',
content
content: asAsyncIterable(content)
}], block))

if (!imported) {
Expand Down
21 changes: 11 additions & 10 deletions packages/ipfs-unixfs-exporter/test/exporter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const blockApi = require('./helpers/block')
const uint8ArrayFromString = require('uint8arrays/from-string')
const uint8ArrayToString = require('uint8arrays/to-string')
const uint8ArrayConcat = require('uint8arrays/concat')
const asAsyncIterable = require('./helpers/as-async-iterable')

const ONE_MEG = Math.pow(1024, 2)

Expand Down Expand Up @@ -79,7 +80,7 @@ describe('exporter', () => {
async function addTestFile ({ file, strategy = 'balanced', path = '/foo', maxChunkSize, rawLeaves }) {
const result = await all(importer([{
path,
content: file
content: asAsyncIterable(file)
}], block, {
strategy,
rawLeaves,
Expand Down Expand Up @@ -195,7 +196,7 @@ describe('exporter', () => {

const files = await all(importer([{
path: filePath,
content: smallFile
content: asAsyncIterable(smallFile)
}], block))

const path = `/ipfs/${files[1].cid.toBaseEncodedString()}/${fileName}`
Expand All @@ -211,7 +212,7 @@ describe('exporter', () => {

const files = await all(importer([{
path: filePath,
content: smallFile
content: asAsyncIterable(smallFile)
}], block))

const path = `/ipfs/${files[1].cid.toBaseEncodedString()}/${fileName}`
Expand Down Expand Up @@ -613,7 +614,7 @@ describe('exporter', () => {
it('exports a large file > 1mb imported with raw leaves', async () => {
const imported = await first(importer([{
path: '1.2MiB.txt',
content: bigFile
content: asAsyncIterable(bigFile)
}], block, {
rawLeaves: true
}))
Expand Down Expand Up @@ -890,7 +891,7 @@ describe('exporter', () => {

const imported = await first(importer([{
path: '200Bytes.txt',
content: bigFile
content: asAsyncIterable(bigFile)
}], block, {
rawLeaves: true
}))
Expand All @@ -915,7 +916,7 @@ describe('exporter', () => {
it('exports a raw leaf', async () => {
const imported = await first(importer([{
path: '200Bytes.txt',
content: smallFile
content: asAsyncIterable(smallFile)
}], block, {
rawLeaves: true
}))
Expand Down Expand Up @@ -1022,7 +1023,7 @@ describe('exporter', () => {
it('exports a node with depth', async () => {
const imported = await all(importer([{
path: '/foo/bar/baz.txt',
content: uint8ArrayFromString('hello world')
content: asAsyncIterable(uint8ArrayFromString('hello world'))
}], block))

const exported = await exporter(imported[0].cid, ipld)
Expand All @@ -1033,13 +1034,13 @@ describe('exporter', () => {
it('exports a node recursively with depth', async () => {
const dir = await last(importer([{
path: '/foo/bar/baz.txt',
content: uint8ArrayFromString('hello world')
content: asAsyncIterable(uint8ArrayFromString('hello world'))
}, {
path: '/foo/qux.txt',
content: uint8ArrayFromString('hello world')
content: asAsyncIterable(uint8ArrayFromString('hello world'))
}, {
path: '/foo/bar/quux.txt',
content: uint8ArrayFromString('hello world')
content: asAsyncIterable(uint8ArrayFromString('hello world'))
}], block))

if (!dir) {
Expand Down
14 changes: 14 additions & 0 deletions packages/ipfs-unixfs-exporter/test/helpers/as-async-iterable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict'

/**
* @param {Uint8Array | Uint8Array[]} arr
*/
async function * asAsyncIterable (arr) {
if (!Array.isArray(arr)) {
arr = [arr]
}

yield * arr
}

module.exports = asAsyncIterable
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const blockApi = require('./helpers/block')
const uint8ArrayFromString = require('uint8arrays/from-string')
const uint8ArrayToString = require('uint8arrays/to-string')
const uint8ArrayConcat = require('uint8arrays/concat')
const asAsyncIterable = require('./helpers/as-async-iterable')

/**
* @typedef {import('../src').UnixFSEntry} UnixFSEntry
Expand All @@ -37,7 +38,7 @@ describe('builder: directory sharding', () => {
const content = uint8ArrayFromString('i have the best bytes')
const nodes = await all(importer([{
path: 'a/b',
content
content: asAsyncIterable(content)
}], block, {
shardSplitThreshold: Infinity // never shard
}))
Expand Down Expand Up @@ -73,7 +74,7 @@ describe('builder: directory sharding', () => {
it('yields a sharded dir', async () => {
const nodes = await all(importer([{
path: 'a/b',
content: uint8ArrayFromString('i have the best bytes')
content: asAsyncIterable(uint8ArrayFromString('i have the best bytes'))
}], block, {
shardSplitThreshold: 0 // always shard
}))
Expand All @@ -95,7 +96,7 @@ describe('builder: directory sharding', () => {
const content = 'i have the best bytes'
const nodes = await all(importer([{
path: 'a/b',
content: uint8ArrayFromString(content)
content: asAsyncIterable(uint8ArrayFromString(content))
}], block, {
shardSplitThreshold: Infinity // never shard
}))
Expand Down Expand Up @@ -132,7 +133,7 @@ describe('builder: directory sharding', () => {
const content = 'i have the best bytes'
const nodes = await all(importer([{
path: 'a/b',
content: uint8ArrayFromString(content)
content: asAsyncIterable(uint8ArrayFromString(content))
}], block, {
shardSplitThreshold: 0 // always shard
}))
Expand Down Expand Up @@ -177,7 +178,7 @@ describe('builder: directory sharding', () => {
for (let i = 0; i < maxDirs; i++) {
yield {
path: 'big/' + i.toString().padStart(4, '0'),
content: uint8ArrayFromString(i.toString())
content: asAsyncIterable(uint8ArrayFromString(i.toString()))
}
}
}
Expand All @@ -196,7 +197,7 @@ describe('builder: directory sharding', () => {
for (let i = 0; i < maxDirs; i++) {
yield {
path: 'big/' + i.toString().padStart(4, '0'),
content: uint8ArrayFromString(i.toString())
content: asAsyncIterable(uint8ArrayFromString(i.toString()))
}
}
}
Expand Down Expand Up @@ -249,7 +250,7 @@ describe('builder: directory sharding', () => {

yield {
path: dir.concat(i.toString().padStart(4, '0')).join('/'),
content: uint8ArrayFromString(i.toString())
content: asAsyncIterable(uint8ArrayFromString(i.toString()))
}

pending--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const blockApi = require('./helpers/block')
const uint8ArrayFromString = require('uint8arrays/from-string')
const uint8ArrayToString = require('uint8arrays/to-string')
const uint8ArrayConcat = require('uint8arrays/concat')
const asAsyncIterable = require('./helpers/as-async-iterable')

describe('import and export: directory', () => {
const rootHash = 'QmdCrquDwd7RfZ6GCZFEVADwe8uyyw1YmF9mtAB7etDgmK'
Expand All @@ -31,16 +32,16 @@ describe('import and export: directory', () => {

const source = [{
path: 'a/b/c/d/e',
content: uint8ArrayFromString('banana')
content: asAsyncIterable(uint8ArrayFromString('banana'))
}, {
path: 'a/b/c/d/f',
content: uint8ArrayFromString('strawberry')
content: asAsyncIterable(uint8ArrayFromString('strawberry'))
}, {
path: 'a/b/g',
content: uint8ArrayFromString('ice')
content: asAsyncIterable(uint8ArrayFromString('ice'))
}, {
path: 'a/b/h',
content: uint8ArrayFromString('cream')
content: asAsyncIterable(uint8ArrayFromString('cream'))
}]

const files = await all(importer(source, block))
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-unixfs-exporter/test/import-export.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const loadFixture = require('aegir/utils/fixtures')
const isNode = require('detect-node')
const bigFile = loadFixture((isNode ? __dirname : 'test') + '/fixtures/1.2MiB.txt')
const blockApi = require('./helpers/block')
const asAsyncIterable = require('./helpers/as-async-iterable')

const { importer } = require('ipfs-unixfs-importer')
const { exporter } = require('../src')
Expand Down Expand Up @@ -42,7 +43,7 @@ describe('import and export', function () {

it('imports and exports', async () => {
const path = `${strategy}-big.dat`
const values = [{ path: path, content: bigFile }]
const values = [{ path: path, content: asAsyncIterable(bigFile) }]

// @ts-ignore
for await (const file of importer(values, block, importerOptions)) {
Expand Down
Loading