New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ipfs-unixfs-importer

Package Overview
Dependencies
Maintainers
3
Versions
136
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ipfs-unixfs-importer - npm Package Compare versions

Comparing version 14.0.0 to 14.0.1

5

dist/src/dag-builder/index.js

@@ -42,3 +42,3 @@ import { dirBuilder } from './dir.js';

}
if (entry.content != null) {
if (isFileCandidate(entry)) {
const file = {

@@ -68,2 +68,5 @@ path: entry.path,

}
function isFileCandidate(entry) {
return entry.content != null;
}
//# sourceMappingURL=index.js.map

50

dist/src/index.d.ts

@@ -11,8 +11,14 @@ import { DAGBuilder } from './dag-builder/index.js';

export type ImportContent = ByteStream | Uint8Array;
export interface ImportCandidate {
export interface FileCandidate {
path?: string;
content?: ImportContent;
content: ImportContent;
mtime?: Mtime;
mode?: number;
}
export interface DirectoryCandidate {
path: string;
mtime?: Mtime;
mode?: number;
}
export type ImportCandidate = FileCandidate | DirectoryCandidate;
export interface File {

@@ -163,3 +169,3 @@ content: AsyncIterable<Uint8Array>;

}
export type ImportCandidateStream = AsyncIterable<ImportCandidate> | Iterable<ImportCandidate>;
export type ImportCandidateStream = AsyncIterable<FileCandidate | DirectoryCandidate> | Iterable<FileCandidate | DirectoryCandidate>;
/**

@@ -194,4 +200,4 @@ * The importer creates UnixFS DAGs and stores the blocks that make

/**
* `importContent` is similar to `importer` except it accepts a single
* `ImportCandidate` and returns a promise of a single `ImportResult`
* `importFile` is similar to `importer` except it accepts a single
* `FileCandidate` and returns a promise of a single `ImportResult`
* instead of a stream of results.

@@ -202,3 +208,3 @@ *

* ```typescript
* import { importOne } from 'ipfs-unixfs-importer'
* import { importFile } from 'ipfs-unixfs-importer'
* import { MemoryBlockstore } from 'blockstore-core'

@@ -209,3 +215,3 @@ *

*
* const input = {
* const input: FileCandidate = {
* path: './foo.txt',

@@ -215,7 +221,29 @@ * content: Uint8Array.from([0, 1, 2, 3, 4])

*
* const entry = await importContent(input, blockstore)
* const entry = await importFile(input, blockstore)
* ```
*/
export declare function importContent(content: ImportCandidate, blockstore: Blockstore, options?: ImporterOptions): Promise<ImportResult>;
export declare function importFile(content: FileCandidate, blockstore: Blockstore, options?: ImporterOptions): Promise<ImportResult>;
/**
* `importDir` is similar to `importer` except it accepts a single
* `DirectoryCandidate` and returns a promise of a single `ImportResult`
* instead of a stream of results.
*
* @example
*
* ```typescript
* import { importDirectory } from 'ipfs-unixfs-importer'
* import { MemoryBlockstore } from 'blockstore-core'
*
* // store blocks in memory, other blockstores are available
* const blockstore = new MemoryBlockstore()
*
* const input: DirectoryCandidate = {
* path: './foo.txt'
* }
*
* const entry = await importDirectory(input, blockstore)
* ```
*/
export declare function importDirectory(content: DirectoryCandidate, blockstore: Blockstore, options?: ImporterOptions): Promise<ImportResult>;
/**
* `importBytes` accepts a single Uint8Array and returns a promise

@@ -227,3 +255,3 @@ * of a single `ImportResult`.

* ```typescript
* import { importOne } from 'ipfs-unixfs-importer'
* import { importBytes } from 'ipfs-unixfs-importer'
* import { MemoryBlockstore } from 'blockstore-core'

@@ -247,3 +275,3 @@ *

* ```typescript
* import { importOne } from 'ipfs-unixfs-importer'
* import { importByteStream } from 'ipfs-unixfs-importer'
* import { MemoryBlockstore } from 'blockstore-core'

@@ -250,0 +278,0 @@ *

@@ -85,4 +85,4 @@ import parallelBatch from 'it-parallel-batch';

/**
* `importContent` is similar to `importer` except it accepts a single
* `ImportCandidate` and returns a promise of a single `ImportResult`
* `importFile` is similar to `importer` except it accepts a single
* `FileCandidate` and returns a promise of a single `ImportResult`
* instead of a stream of results.

@@ -93,3 +93,3 @@ *

* ```typescript
* import { importOne } from 'ipfs-unixfs-importer'
* import { importFile } from 'ipfs-unixfs-importer'
* import { MemoryBlockstore } from 'blockstore-core'

@@ -100,3 +100,3 @@ *

*
* const input = {
* const input: FileCandidate = {
* path: './foo.txt',

@@ -106,6 +106,6 @@ * content: Uint8Array.from([0, 1, 2, 3, 4])

*
* const entry = await importContent(input, blockstore)
* const entry = await importFile(input, blockstore)
* ```
*/
export async function importContent(content, blockstore, options = {}) {
export async function importFile(content, blockstore, options = {}) {
const result = await first(importer([content], blockstore, options));

@@ -118,2 +118,30 @@ if (result == null) {

/**
* `importDir` is similar to `importer` except it accepts a single
* `DirectoryCandidate` and returns a promise of a single `ImportResult`
* instead of a stream of results.
*
* @example
*
* ```typescript
* import { importDirectory } from 'ipfs-unixfs-importer'
* import { MemoryBlockstore } from 'blockstore-core'
*
* // store blocks in memory, other blockstores are available
* const blockstore = new MemoryBlockstore()
*
* const input: DirectoryCandidate = {
* path: './foo.txt'
* }
*
* const entry = await importDirectory(input, blockstore)
* ```
*/
export async function importDirectory(content, blockstore, options = {}) {
const result = await first(importer([content], blockstore, options));
if (result == null) {
throw errcode(new Error('Nothing imported'), 'ERR_INVALID_PARAMS');
}
return result;
}
/**
* `importBytes` accepts a single Uint8Array and returns a promise

@@ -125,3 +153,3 @@ * of a single `ImportResult`.

* ```typescript
* import { importOne } from 'ipfs-unixfs-importer'
* import { importBytes } from 'ipfs-unixfs-importer'
* import { MemoryBlockstore } from 'blockstore-core'

@@ -138,3 +166,3 @@ *

export async function importBytes(buf, blockstore, options = {}) {
return await importContent({
return await importFile({
content: buf

@@ -150,3 +178,3 @@ }, blockstore, options);

* ```typescript
* import { importOne } from 'ipfs-unixfs-importer'
* import { importByteStream } from 'ipfs-unixfs-importer'
* import { MemoryBlockstore } from 'blockstore-core'

@@ -166,3 +194,3 @@ *

export async function importByteStream(bufs, blockstore, options = {}) {
return await importContent({
return await importFile({
content: bufs

@@ -169,0 +197,0 @@ }, blockstore, options);

@@ -10,5 +10,6 @@ {

"Directory": "https://ipfs.github.io/js-ipfs-unixfs/interfaces/ipfs_unixfs_importer.Directory.html",
"DirectoryCandidate": "https://ipfs.github.io/js-ipfs-unixfs/interfaces/ipfs_unixfs_importer.DirectoryCandidate.html",
"File": "https://ipfs.github.io/js-ipfs-unixfs/interfaces/ipfs_unixfs_importer.File.html",
"FileCandidate": "https://ipfs.github.io/js-ipfs-unixfs/interfaces/ipfs_unixfs_importer.FileCandidate.html",
"HamtHashFn": "https://ipfs.github.io/js-ipfs-unixfs/interfaces/ipfs_unixfs_importer.HamtHashFn.html",
"ImportCandidate": "https://ipfs.github.io/js-ipfs-unixfs/interfaces/ipfs_unixfs_importer.ImportCandidate.html",
"ImportResult": "https://ipfs.github.io/js-ipfs-unixfs/interfaces/ipfs_unixfs_importer.ImportResult.html",

@@ -20,2 +21,3 @@ "ImporterOptions": "https://ipfs.github.io/js-ipfs-unixfs/interfaces/ipfs_unixfs_importer.ImporterOptions.html",

"ByteStream": "https://ipfs.github.io/js-ipfs-unixfs/types/ipfs_unixfs_importer.ByteStream.html",
"ImportCandidate": "https://ipfs.github.io/js-ipfs-unixfs/types/ipfs_unixfs_importer.ImportCandidate.html",
"ImportCandidateStream": "https://ipfs.github.io/js-ipfs-unixfs/types/ipfs_unixfs_importer.ImportCandidateStream.html",

@@ -25,4 +27,5 @@ "ImportContent": "https://ipfs.github.io/js-ipfs-unixfs/types/ipfs_unixfs_importer.ImportContent.html",

"importBytes": "https://ipfs.github.io/js-ipfs-unixfs/functions/ipfs_unixfs_importer.importBytes.html",
"importContent": "https://ipfs.github.io/js-ipfs-unixfs/functions/ipfs_unixfs_importer.importContent-1.html",
"importDirectory": "https://ipfs.github.io/js-ipfs-unixfs/functions/ipfs_unixfs_importer.importDirectory.html",
"importFile": "https://ipfs.github.io/js-ipfs-unixfs/functions/ipfs_unixfs_importer.importFile.html",
"importer": "https://ipfs.github.io/js-ipfs-unixfs/functions/ipfs_unixfs_importer.importer.html"
}
{
"name": "ipfs-unixfs-importer",
"version": "14.0.0",
"version": "14.0.1",
"description": "JavaScript implementation of the UnixFs importer used by IPFS",

@@ -5,0 +5,0 @@ "license": "Apache-2.0 OR MIT",

@@ -17,3 +17,4 @@ # ipfs-unixfs-importer <!-- omit in toc -->

- [const stream = importer(source, blockstore \[, options\])](#const-stream--importersource-blockstore--options)
- [const result = await importContent(content, blockstore \[, options\])](#const-result--await-importcontentcontent-blockstore--options)
- [const result = await importFile(content, blockstore \[, options\])](#const-result--await-importfilecontent-blockstore--options)
- [const result = await importDirectory(content, blockstore \[, options\])](#const-result--await-importdirectorycontent-blockstore--options)
- [const result = await importBytes(buf, blockstore \[, options\])](#const-result--await-importbytesbuf-blockstore--options)

@@ -101,3 +102,3 @@ - [const result = await importByteStream(source, blockstore \[, options\])](#const-result--await-importbytestreamsource-blockstore--options)

```js
import { importer, importContent, importBytes } from 'ipfs-unixfs-importer'
import { importer, importFile, importDir, importBytes, importByteStream } from 'ipfs-unixfs-importer'
```

@@ -124,6 +125,10 @@

### const result = await importContent(content, blockstore \[, options])
### const result = await importFile(content, blockstore \[, options])
A convenience function for importing a single file or directory.
### const result = await importDirectory(content, blockstore \[, options])
A convenience function for importing a directory - note this is non-recursive, to import recursively use the [importer](#const-stream--importersource-blockstore--options) function.
### const result = await importBytes(buf, blockstore \[, options])

@@ -130,0 +135,0 @@

import { dirBuilder, DirBuilderOptions } from './dir.js'
import { fileBuilder, FileBuilderOptions } from './file.js'
import errCode from 'err-code'
import type { Directory, File, ImportCandidate, InProgressImportResult } from '../index.js'
import type { Directory, File, FileCandidate, ImportCandidate, InProgressImportResult } from '../index.js'
import type { Blockstore } from 'interface-blockstore'

@@ -62,3 +62,3 @@ import type { ChunkValidator } from './validate-chunks.js'

if (entry.content != null) {
if (isFileCandidate(entry)) {
const file: File = {

@@ -88,1 +88,5 @@ path: entry.path,

}
function isFileCandidate (entry: any): entry is FileCandidate {
return entry.content != null
}

@@ -19,5 +19,5 @@ import parallelBatch from 'it-parallel-batch'

export interface ImportCandidate {
export interface FileCandidate {
path?: string
content?: ImportContent
content: ImportContent
mtime?: Mtime

@@ -27,2 +27,10 @@ mode?: number

export interface DirectoryCandidate {
path: string
mtime?: Mtime
mode?: number
}
export type ImportCandidate = FileCandidate | DirectoryCandidate
export interface File {

@@ -185,3 +193,3 @@ content: AsyncIterable<Uint8Array>

export type ImportCandidateStream = AsyncIterable<ImportCandidate> | Iterable<ImportCandidate>
export type ImportCandidateStream = AsyncIterable<FileCandidate | DirectoryCandidate> | Iterable<FileCandidate | DirectoryCandidate>

@@ -216,3 +224,3 @@ /**

export async function * importer (source: ImportCandidateStream, blockstore: Blockstore, options: ImporterOptions = {}): AsyncGenerator<ImportResult, void, unknown> {
let candidates: AsyncIterable<ImportCandidate> | Iterable<ImportCandidate>
let candidates: AsyncIterable<FileCandidate | DirectoryCandidate> | Iterable<FileCandidate | DirectoryCandidate>

@@ -268,4 +276,4 @@ if (Symbol.asyncIterator in source || Symbol.iterator in source) {

/**
* `importContent` is similar to `importer` except it accepts a single
* `ImportCandidate` and returns a promise of a single `ImportResult`
* `importFile` is similar to `importer` except it accepts a single
* `FileCandidate` and returns a promise of a single `ImportResult`
* instead of a stream of results.

@@ -276,3 +284,3 @@ *

* ```typescript
* import { importOne } from 'ipfs-unixfs-importer'
* import { importFile } from 'ipfs-unixfs-importer'
* import { MemoryBlockstore } from 'blockstore-core'

@@ -283,3 +291,3 @@ *

*
* const input = {
* const input: FileCandidate = {
* path: './foo.txt',

@@ -289,6 +297,6 @@ * content: Uint8Array.from([0, 1, 2, 3, 4])

*
* const entry = await importContent(input, blockstore)
* const entry = await importFile(input, blockstore)
* ```
*/
export async function importContent (content: ImportCandidate, blockstore: Blockstore, options: ImporterOptions = {}): Promise<ImportResult> {
export async function importFile (content: FileCandidate, blockstore: Blockstore, options: ImporterOptions = {}): Promise<ImportResult> {
const result = await first(importer([content], blockstore, options))

@@ -304,2 +312,33 @@

/**
* `importDir` is similar to `importer` except it accepts a single
* `DirectoryCandidate` and returns a promise of a single `ImportResult`
* instead of a stream of results.
*
* @example
*
* ```typescript
* import { importDirectory } from 'ipfs-unixfs-importer'
* import { MemoryBlockstore } from 'blockstore-core'
*
* // store blocks in memory, other blockstores are available
* const blockstore = new MemoryBlockstore()
*
* const input: DirectoryCandidate = {
* path: './foo.txt'
* }
*
* const entry = await importDirectory(input, blockstore)
* ```
*/
export async function importDirectory (content: DirectoryCandidate, blockstore: Blockstore, options: ImporterOptions = {}): Promise<ImportResult> {
const result = await first(importer([content], blockstore, options))
if (result == null) {
throw errcode(new Error('Nothing imported'), 'ERR_INVALID_PARAMS')
}
return result
}
/**
* `importBytes` accepts a single Uint8Array and returns a promise

@@ -311,3 +350,3 @@ * of a single `ImportResult`.

* ```typescript
* import { importOne } from 'ipfs-unixfs-importer'
* import { importBytes } from 'ipfs-unixfs-importer'
* import { MemoryBlockstore } from 'blockstore-core'

@@ -324,3 +363,3 @@ *

export async function importBytes (buf: ImportContent, blockstore: Blockstore, options: ImporterOptions = {}): Promise<ImportResult> {
return await importContent({
return await importFile({
content: buf

@@ -337,3 +376,3 @@ }, blockstore, options)

* ```typescript
* import { importOne } from 'ipfs-unixfs-importer'
* import { importByteStream } from 'ipfs-unixfs-importer'
* import { MemoryBlockstore } from 'blockstore-core'

@@ -353,5 +392,5 @@ *

export async function importByteStream (bufs: ByteStream, blockstore: Blockstore, options: ImporterOptions = {}): Promise<ImportResult> {
return await importContent({
return await importFile({
content: bufs
}, blockstore, options)
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc