Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

files.add with pull stream does not work #745

Closed
alanshaw opened this issue Apr 20, 2018 · 0 comments · Fixed by #746
Closed

files.add with pull stream does not work #745

alanshaw opened this issue Apr 20, 2018 · 0 comments · Fixed by #746
Assignees

Comments

@alanshaw
Copy link
Contributor

  • Version: 20.0.1
  • Platform: macOS Node.js 9.11.1
  • Subsystem: files

Type: Bug

Severity: High

Description:

Using files.add(pull stream) does not work

Steps to reproduce the error:

  1. addPullStream with chunks of { content: [pull stream] }

    const pull = require('pull-stream')
    const ipfs = require('ipfs-api')()
    
    pull(
      pull.values([{ content: pull.values([Buffer.from('test')]) }]),
      ipfs.files.addPullStream(),
      pull.collect(console.log)
    )

    output:

    TypeError: content.once is not a function
        at Multipart._pushFile (/Users/alan/Desktop/test/node_modules/ipfs-api/src/utils/multipart.js:80:13)
        at Multipart._maybeDrain (/Users/alan/Desktop/test/node_modules/ipfs-api/src/utils/multipart.js:48:14)
        at Multipart._transform (/Users/alan/Desktop/test/node_modules/ipfs-api/src/utils/multipart.js:40:10)
        at Multipart.Transform._read (_stream_transform.js:185:10)
        at Multipart.Transform._write (_stream_transform.js:173:12)
        at doWrite (_stream_writable.js:410:12)
        at writeOrBuffer (_stream_writable.js:396:5)
        at Multipart.Writable.write (_stream_writable.js:294:11)
        at eachSeries (/Users/alan/Desktop/test/node_modules/ipfs-api/src/utils/send-files-stream.js:51:35)
        at /Users/alan/Desktop/test/node_modules/async/internal/withoutIndex.js:9:16 []
    
  2. add with pull stream (promise)

    const pull = require('pull-stream')
    const ipfs = require('ipfs-api')()
    
    ipfs.files.add(pull.values([Buffer.from('test')]))
      .then(console.log)
      .catch(console.error)

    output:

    /Users/alan/Desktop/test/node_modules/wrappy/wrappy.js:27
          Object.keys(cb).forEach(function (k) {
                 ^
    
    TypeError: Cannot convert undefined or null to object
        at Function.keys (<anonymous>)
        at wrapper (/Users/alan/Desktop/test/node_modules/wrappy/wrappy.js:27:14)
        at Function.promisify (/Users/alan/Desktop/test/node_modules/ipfs-api/src/files/add.js:20:22)
        at Object.add (/Users/alan/Desktop/test/node_modules/promisify-es6/index.js:32:27)
        at Object.<anonymous> (/Users/alan/Desktop/test/ipfs-api-pull.test.js:28:12)
        at Module._compile (internal/modules/cjs/loader.js:654:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
        at Module.load (internal/modules/cjs/loader.js:566:32)
        at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
        at Function.Module._load (internal/modules/cjs/loader.js:498:3)
    
  3. add with pull stream (callback)

    const pull = require('pull-stream')
    const ipfs = require('ipfs-api')()
    
    ipfs.files.add(pull.values([Buffer.from('test')]), console.log)

    output:

    Error: first arg must be a buffer, readable stream, an object or array of objects
        at Function.promisify (/Users/alan/Desktop/test/node_modules/ipfs-api/src/files/add.js:34:23)
        at Object.add (/Users/alan/Desktop/test/node_modules/promisify-es6/index.js:32:27)
        at Object.<anonymous> (/Users/alan/Desktop/test/ipfs-api-pull.test.js:52:12)
        at Module._compile (internal/modules/cjs/loader.js:654:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
        at Module.load (internal/modules/cjs/loader.js:566:32)
        at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
        at Function.Module._load (internal/modules/cjs/loader.js:498:3)
        at Function.Module.runMain (internal/modules/cjs/loader.js:695:10)
        at startup (internal/bootstrap/node.js:201:19)
    
  4. add with [{ content: [pull stream] }]

    const pull = require('pull-stream')
    const ipfs = require('ipfs-api')()
    
    ipfs.files.add([{ content: pull.values([Buffer.from('test')]) }])
      .then(console.log)
      .catch(console.error)

    output:

    TypeError: content.once is not a function
        at Multipart._pushFile (/Users/alan/Desktop/test/node_modules/ipfs-api/src/utils/multipart.js:80:13)
        at Multipart._maybeDrain (/Users/alan/Desktop/test/node_modules/ipfs-api/src/utils/multipart.js:48:14)
        at Multipart._transform (/Users/alan/Desktop/test/node_modules/ipfs-api/src/utils/multipart.js:40:10)
        at Multipart.Transform._read (_stream_transform.js:185:10)
        at Multipart.Transform._write (_stream_transform.js:173:12)
        at doWrite (_stream_writable.js:410:12)
        at writeOrBuffer (_stream_writable.js:396:5)
        at Multipart.Writable.write (_stream_writable.js:294:11)
        at eachSeries (/Users/alan/Desktop/test/node_modules/ipfs-api/src/utils/send-files-stream.js:51:35)
        at /Users/alan/Desktop/test/node_modules/async/internal/withoutIndex.js:9:16
    

Some of these operations work directly on a js-ipfs instance. I've opened ipfs/js-ipfs#1317 for the ones that do not.

Files spec (which allows these combinations) for reference: https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant