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

Commit 1ad6001

Browse files
authoredAug 9, 2021
feat: make ipfs.get output tarballs (#3785)
`ipfs get` on the cli writes files/folders to disk, also tarballs and gzipped tarballs. Also gzipped individual files. In the API it's very similar to `ipfs.ls`. Make it more like the cli so there's a clear reason to use one or the other. Also adds types to `interface-ipfs-core` to better catch broken types in `ipfs-core-types`. BREAKING CHANGE: the output type of `ipfs.get` has changed and the `recursive` option has been removed from `ipfs.ls` since it was not supported everywhere
1 parent 79f661e commit 1ad6001

File tree

217 files changed

+3316
-1556
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

217 files changed

+3316
-1556
lines changed
 

‎.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ jobs:
8484
- stage: test
8585
name: lint
8686
script:
87+
- npm run build
8788
- npm run lint -- $RUN_SINCE --concurrency 1
8889

8990
- stage: test

‎docs/core-api/FILES.md

+15-29
Original file line numberDiff line numberDiff line change
@@ -447,53 +447,39 @@ An optional object which may have the following keys:
447447

448448
| Name | Type | Default | Description |
449449
| ---- | ---- | ------- | ----------- |
450+
| archive | `boolean` | `undefined` | Return the file/directory in a tarball |
451+
| compress | `boolean` | `false` | Gzip the returned stream |
452+
| compressionLevel | `Number` | `undefined` | How much compression to apply (1-9) |
450453
| timeout | `Number` | `undefined` | A timeout in ms |
451454
| signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call |
452455

453456
#### Returns
454457

455458
| Type | Description |
456459
| -------- | -------- |
457-
| `AsyncIterable<Object>` | An async iterable that yields objects representing the files |
460+
| `AsyncIterable<Uint8Array>` | An async iterable that yields bytes |
458461

459-
Each yielded object is of the form:
462+
What is streamed as a response depends on the options passed and what the `ipfsPath` resolves to.
460463

461-
```js
462-
{
463-
type: string, // 'file' or 'dir'
464-
path: string, // a deeply nested path within the directory structure
465-
content?: <AsyncIterable<Uint8Array>>, // only present if `type` is 'file'
466-
mode: Number, // implicit if not provided - 0644 for files, 0755 for directories
467-
mtime?: { secs: Number, nsecs: Number }
468-
}
469-
```
470-
471-
Here, each `path` corresponds to the name of a file, and `content` is an async iterable with the file contents.
464+
1. If `ipfsPath` resolves to a file:
465+
* By default you will get a tarball containing the file
466+
* Pass `compress: true` (and an optional `compressionLevel`) to instead get the gzipped file contents
467+
* Pass `compress: true` (and an optional `compressionLevel`) AND `archive: true` to get a gzipped tarball containing the file
468+
2. If `ipfsPath` resolves to a directory:
469+
* By default you will get a tarball containing the contents of the directory
470+
* Passing `compress: true` will cause an error
471+
* Pass `compress: true` (and an optional `compressionLevel`) AND `archive: true` to get a gzipped tarball containing the contents of the directory
472472

473473
#### Example
474474

475475
```JavaScript
476476
const cid = 'QmQ2r6iMNpky5f1m4cnm3Yqw8VSvjuKpTcK1X7dBR1LkJF'
477477

478-
for await (const file of ipfs.get(cid)) {
479-
console.log(file.type, file.path)
480-
481-
if (!file.content) continue;
482-
483-
const content = []
484-
485-
for await (const chunk of file.content) {
486-
content.push(chunk)
487-
}
488-
489-
console.log(content)
478+
for await (const buf of ipfs.get(cid)) {
479+
// do something with buf
490480
}
491481
```
492482

493-
When invoking this method via the HTTP API client, the response arrives as a stream containing either the entire contents of the file (if the passed [CID][] resolves to a file) or recursive directory tree and all files contained therein (if the passed [CID][] resolves to a directory).
494-
495-
If you are iterating over a directory, in order to proceed to the next entry in the stream, you must consume the `content` field of the current entry if it is present.
496-
497483
A great source of [examples](https://github.com/ipfs/js-ipfs/blob/master/packages/interface-ipfs-core/src/get.js) can be found in the tests for this API.
498484

499485
### `ipfs.ls(ipfsPath)`

0 commit comments

Comments
 (0)
This repository has been archived.