ipfs-utils
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -0,1 +1,18 @@ | ||
<a name="0.5.0"></a> | ||
# [0.5.0](https://github.com/ipfs/js-ipfs-utils/compare/v0.4.0...v0.5.0) (2019-12-06) | ||
### Features | ||
* convert to async iterators ([#15](https://github.com/ipfs/js-ipfs-utils/issues/15)) ([251eff0](https://github.com/ipfs/js-ipfs-utils/commit/251eff0)) | ||
* support unixfs metadata and formatting it ([#14](https://github.com/ipfs/js-ipfs-utils/issues/14)) ([173e4bf](https://github.com/ipfs/js-ipfs-utils/commit/173e4bf)) | ||
### BREAKING CHANGES | ||
* In order to support metadata on intermediate directories, globSource in this module will now emit directories and files where previously it only emitted files. | ||
* Support for Node.js streams and Pull Streams has been removed | ||
<a name="0.4.0"></a> | ||
@@ -2,0 +19,0 @@ # [0.4.0](https://github.com/ipfs/js-ipfs-utils/compare/v0.3.0...v0.4.0) (2019-09-19) |
{ | ||
"name": "ipfs-utils", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "Package to aggregate shared logic and dependencies for the IPFS ecosystem", | ||
@@ -32,19 +32,14 @@ "main": "src/index.js", | ||
"fs-extra": "^8.1.0", | ||
"is-buffer": "^2.0.3", | ||
"is-electron": "^2.2.0", | ||
"is-pull-stream": "0.0.0", | ||
"is-stream": "^2.0.0", | ||
"it-glob": "0.0.4", | ||
"kind-of": "^6.0.2", | ||
"pull-stream-to-async-iterator": "^1.0.2", | ||
"readable-stream": "^3.4.0" | ||
"it-glob": "0.0.7", | ||
"ky": "^0.16.1", | ||
"ky-universal": "^0.3.0", | ||
"stream-to-it": "^0.2.0" | ||
}, | ||
"devDependencies": { | ||
"aegir": "^20.3.0", | ||
"async-iterator-all": "^1.0.0", | ||
"aegir": "^20.4.1", | ||
"chai": "^4.2.0", | ||
"chai-as-promised": "^7.1.1", | ||
"dirty-chai": "^2.0.1", | ||
"pull-stream": "^3.6.13", | ||
"readable-stream-2": "npm:readable-stream@^2.0.0" | ||
"it-all": "^1.0.1" | ||
}, | ||
@@ -51,0 +46,0 @@ "contributors": [ |
@@ -7,3 +7,2 @@ 'use strict' | ||
const errCode = require('err-code') | ||
const kindOf = require('kind-of') | ||
@@ -19,2 +18,6 @@ /** | ||
* @param {Boolean} [options.followSymlinks] follow symlinks | ||
* @param {Boolean} [options.preserveMode] preserve mode | ||
* @param {Boolean} [options.preserveMtime] preserve mtime | ||
* @param {Boolean} [options.mode] mode to use - if preserveMode is true this will be ignored | ||
* @param {Boolean} [options.mtime] mtime to use - if preserveMtime is true this will be ignored | ||
* @yields {Object} File objects in the form `{ path: String, content: AsyncIterator<Buffer> }` | ||
@@ -25,3 +28,3 @@ */ | ||
if (kindOf(paths) === 'string') { | ||
if (typeof paths === 'string') { | ||
paths = [paths] | ||
@@ -53,9 +56,35 @@ } | ||
for await (const entry of toGlobSource({ path, type: stat.isDirectory() ? 'dir' : 'file', prefix }, globSourceOptions)) { | ||
yield entry | ||
let mode = options.mode | ||
if (options.preserveMode) { | ||
mode = stat.mode | ||
} | ||
let mtime = options.mtime | ||
if (options.preserveMtime) { | ||
mtime = parseInt(stat.mtimeMs / 1000) | ||
} | ||
if (stat.isDirectory()) { | ||
yield { | ||
path: `/${Path.basename(path)}`, | ||
mode, | ||
mtime | ||
} | ||
} | ||
yield * toGlobSource({ | ||
path, | ||
type: stat.isDirectory() ? 'dir' : 'file', | ||
prefix, | ||
mode, | ||
mtime, | ||
preserveMode: options.preserveMode, | ||
preserveMtime: options.preserveMtime | ||
}, globSourceOptions) | ||
} | ||
} | ||
async function * toGlobSource ({ path, type, prefix }, options) { | ||
async function * toGlobSource ({ path, type, prefix, mode, mtime, preserveMode, preserveMtime }, options) { | ||
options = options || {} | ||
@@ -67,4 +96,6 @@ | ||
yield { | ||
path: baseName.replace(prefix, ''), | ||
content: fs.createReadStream(Path.isAbsolute(path) ? path : Path.join(process.cwd(), path)) | ||
path: `/${baseName.replace(prefix, '')}`, | ||
content: fs.createReadStream(Path.isAbsolute(path) ? path : Path.join(process.cwd(), path)), | ||
mode, | ||
mtime | ||
} | ||
@@ -85,3 +116,3 @@ | ||
cwd: path, | ||
nodir: true, | ||
nodir: false, | ||
realpath: false, | ||
@@ -92,5 +123,19 @@ absolute: true | ||
for await (const p of glob(path, '**/*', globOptions)) { | ||
const stat = await fs.stat(p) | ||
if (preserveMode || preserveMtime) { | ||
if (preserveMode) { | ||
mode = stat.mode | ||
} | ||
if (preserveMtime) { | ||
mtime = parseInt(stat.mtimeMs / 1000) | ||
} | ||
} | ||
yield { | ||
path: toPosix(p.replace(prefix, '')), | ||
content: fs.createReadStream(p) | ||
content: stat.isFile() ? fs.createReadStream(p) : undefined, | ||
mode, | ||
mtime | ||
} | ||
@@ -97,0 +142,0 @@ } |
@@ -5,7 +5,3 @@ 'use strict' | ||
const { Buffer } = require('buffer') | ||
const pullStreamToIterable = require('pull-stream-to-async-iterator') | ||
const { isSource } = require('is-pull-stream') | ||
const globalThis = require('../globalthis') | ||
const { Readable } = require('stream') | ||
const Readable3 = require('readable-stream') | ||
@@ -25,4 +21,2 @@ /* | ||
* { path, content: AsyncIterable<Bytes> } [single file] | ||
* { path, content: PullStream<Bytes> } [single file] | ||
* { path, content: Readable<Bytes> } [single file] | ||
* Iterable<Number> [single file] | ||
@@ -38,4 +32,2 @@ * Iterable<Bytes> [single file] | ||
* Iterable<{ path, content: AsyncIterable<Bytes> }> [multiple files] | ||
* Iterable<{ path, content: PullStream<Bytes> }> [multiple files] | ||
* Iterable<{ path, content: Readable<Bytes> }> [multiple files] | ||
* AsyncIterable<Bytes> [single file] | ||
@@ -50,26 +42,2 @@ * AsyncIterable<Bloby> [multiple files] | ||
* AsyncIterable<{ path, content: AsyncIterable<Bytes> }> [multiple files] | ||
* AsyncIterable<{ path, content: PullStream<Bytes> }> [multiple files] | ||
* AsyncIterable<{ path, content: Readable<Bytes> }> [multiple files] | ||
* PullStream<Bytes> [single file] | ||
* PullStream<Bloby> [multiple files] | ||
* PullStream<String> [multiple files] | ||
* PullStream<{ path, content: Bytes }> [multiple files] | ||
* PullStream<{ path, content: Bloby }> [multiple files] | ||
* PullStream<{ path, content: String }> [multiple files] | ||
* PullStream<{ path, content: Iterable<Number> }> [multiple files] | ||
* PullStream<{ path, content: Iterable<Bytes> }> [multiple files] | ||
* PullStream<{ path, content: AsyncIterable<Bytes> }> [multiple files] | ||
* PullStream<{ path, content: PullStream<Bytes> }> [multiple files] | ||
* PullStream<{ path, content: Readable<Bytes> }> [multiple files] | ||
* Readable<Bytes> [single file] | ||
* Readable<Bloby> [multiple files] | ||
* Readable<String> [multiple files] | ||
* Readable<{ path, content: Bytes }> [multiple files] | ||
* Readable<{ path, content: Bloby }> [multiple files] | ||
* Readable<{ path, content: String }> [multiple files] | ||
* Readable<{ path, content: Iterable<Number> }> [multiple files] | ||
* Readable<{ path, content: Iterable<Bytes> }> [multiple files] | ||
* Readable<{ path, content: AsyncIterable<Bytes> }> [multiple files] | ||
* Readable<{ path, content: PullStream<Bytes> }> [multiple files] | ||
* Readable<{ path, content: Readable<Bytes> }> [multiple files] | ||
* ``` | ||
@@ -106,7 +74,2 @@ * Into: | ||
// Readable<?> | ||
if (isOldReadable(input)) { | ||
input = upgradeOldStream(input) | ||
} | ||
// Iterable<?> | ||
@@ -184,33 +147,2 @@ if (input[Symbol.iterator]) { | ||
// PullStream<?> | ||
if (isSource(input)) { | ||
return (async function * () { | ||
const iterator = pullStreamToIterable(input)[Symbol.asyncIterator]() | ||
const first = await iterator.next() | ||
if (first.done) return iterator | ||
// PullStream<Bytes> | ||
if (isBytes(first.value)) { | ||
yield toFileObject((async function * () { // eslint-disable-line require-await | ||
yield first.value | ||
yield * iterator | ||
})()) | ||
return | ||
} | ||
// PullStream<Bloby> | ||
// PullStream<String> | ||
// PullStream<{ path, content }> | ||
if (isFileObject(first.value) || isBloby(first.value) || typeof first.value === 'string') { | ||
yield toFileObject(first.value) | ||
for await (const obj of iterator) { | ||
yield toFileObject(obj) | ||
} | ||
return | ||
} | ||
throw errCode(new Error('Unexpected input: ' + typeof input), 'ERR_UNEXPECTED_INPUT') | ||
})() | ||
} | ||
throw errCode(new Error('Unexpected input: ' + typeof input), 'ERR_UNEXPECTED_INPUT') | ||
@@ -220,3 +152,7 @@ } | ||
function toFileObject (input) { | ||
const obj = { path: input.path || '' } | ||
const obj = { | ||
path: input.path || '', | ||
mode: input.mode, | ||
mtime: input.mtime | ||
} | ||
@@ -245,7 +181,2 @@ if (input.content) { | ||
// Readable<?> | ||
if (isOldReadable(input)) { | ||
input = upgradeOldStream(input) | ||
} | ||
// Iterator<?> | ||
@@ -289,18 +220,5 @@ if (input[Symbol.iterator]) { | ||
// PullStream<Bytes> | ||
if (isSource(input)) { | ||
return pullStreamToIterable(input) | ||
} | ||
throw errCode(new Error(`Unexpected input: ${input}`, 'ERR_UNEXPECTED_INPUT')) | ||
} | ||
function isOldReadable (obj) { | ||
if (obj[Symbol.iterator] || obj[Symbol.asyncIterator]) { | ||
return false | ||
} | ||
return Boolean(obj.readable) | ||
} | ||
function toBuffer (chunk) { | ||
@@ -323,13 +241,2 @@ return isBytes(chunk) ? chunk : Buffer.from(chunk) | ||
function upgradeOldStream (stream) { | ||
if (stream[Symbol.asyncIterator] || stream[Symbol.iterator]) { | ||
return stream | ||
} | ||
// in the browser the stream.Readable is not an async iterator but readble-stream@3 is... | ||
stream[Symbol.asyncIterator] = Readable.prototype[Symbol.asyncIterator] || Readable3.prototype[Symbol.asyncIterator] | ||
return stream | ||
} | ||
function blobToAsyncGenerator (blob) { | ||
@@ -336,0 +243,0 @@ if (typeof blob.stream === 'function') { |
8
5
17
39846
596
+ Addedky@^0.16.1
+ Addedky-universal@^0.3.0
+ Addedstream-to-it@^0.2.0
+ Addedabort-controller@3.0.0(transitive)
+ Addedevent-target-shim@5.0.1(transitive)
+ Addedget-iterator@1.0.2(transitive)
+ Addedit-glob@0.0.7(transitive)
+ Addedky@0.16.2(transitive)
+ Addedky-universal@0.3.0(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addedstream-to-it@0.2.4(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
- Removedis-buffer@^2.0.3
- Removedis-pull-stream@0.0.0
- Removedis-stream@^2.0.0
- Removedkind-of@^6.0.2
- Removedpull-stream-to-async-iterator@^1.0.2
- Removedreadable-stream@^3.4.0
- Removedinherits@2.0.4(transitive)
- Removedis-buffer@2.0.5(transitive)
- Removedis-pull-stream@0.0.0(transitive)
- Removedis-stream@2.0.1(transitive)
- Removedit-glob@0.0.4(transitive)
- Removedkind-of@6.0.3(transitive)
- Removedpull-stream@3.7.0(transitive)
- Removedpull-stream-to-async-iterator@1.0.2(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedutil-deprecate@1.0.2(transitive)
Updatedit-glob@0.0.7