You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

ipfs-utils

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.4.0 to 0.5.0

src/files/format-mode.js

17

CHANGELOG.md

@@ -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)

19

package.json
{
"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') {

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc