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

getReadableStream returns Readable with length 0 after migration to the latest version #1213

Closed
Rkrushanovskij opened this issue Jan 8, 2020 · 2 comments

Comments

@Rkrushanovskij
Copy link

Rkrushanovskij commented Jan 8, 2020

After migration to the latest ipfs-http-client version I faced troubles with getReadableStream.
Versions: 32.0.1 -> 40.1.0

I am uploading file to IPFS from FS using:
ipfs.addFromFs(path, options)
and getting such result:

[
  {
    path: 'test.txt',
    hash: 'Qmcx3cKnJg4dvCZpktXD14D6zFY1E8YqpTZW95BhAVc7KB',
    size: 72
  }
]

AFAIU it means that file uploaded successfully and this hash have some content (non-zero size).

I am trying to get readable stream from IPFS for this file but returned stream is 0 length:
ipfs.getReadableStream(hash)

{
  path: 'Qmcx3cKnJg4dvCZpktXD14D6zFY1E8YqpTZW95BhAVc7KB',
  content: Readable {
    _readableState: ReadableState {
      objectMode: false,
      highWaterMark: 16384,
      buffer: BufferList { head: null, tail: null, length: 0 },
      length: 0,
      pipes: null,
      pipesCount: 0,
      flowing: null,
      ended: false,
      endEmitted: false,
      reading: false,
      sync: true,
      needReadable: false,
      emittedReadable: false,
      readableListening: false,
      resumeScheduled: false,
      paused: true,
      emitClose: true,
      autoDestroy: false,
      destroyed: false,
      defaultEncoding: 'utf8',
      awaitDrain: 0,
      readingMore: false,
      decoder: null,
      encoding: null
    },
    readable: true,
    _read: [AsyncFunction: read],
    _events: [Object: null prototype] {},
    _eventsCount: 0,
    _maxListeners: undefined
  }
}

It is strange that same hash that during uploading had size 72 now displayed as zero-length.

@Rkrushanovskij Rkrushanovskij changed the title getReadableStream returns Readable with length 0 after migrating to the latest ipfs-http-client getReadableStream returns Readable with length 0 after migrating to the latest ipfs-http-client version Jan 8, 2020
@Rkrushanovskij Rkrushanovskij changed the title getReadableStream returns Readable with length 0 after migrating to the latest ipfs-http-client version getReadableStream returns Readable with length 0 after migration to the latest version Jan 8, 2020
@Rkrushanovskij
Copy link
Author

Hello? :(

@alanshaw
Copy link
Contributor

Are you using content._readableState.length? Firstly, I would suggest not depending on this value, by convention underscore prefixed members are considered private and are not usually part of the public API.

Secondly, streams by their nature are not guaranteed to know their length before they are consumed. There is nothing in the public API for streams that allows you to know this.

You could consume the stream and then you'd know the length or you can use ipfs.ls to get size information for a given file.

Hope that helps.

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

No branches or pull requests

2 participants