AgustinCB / docker-api

Docker Remote API driver for node.js. It uses the same modem than dockerode, but the interface is promisified and with a fancier syntax.
GNU General Public License v3.0
306 stars 50 forks source link

Image pull stream comes in batches, not one by one #67

Open MartinMuzatko opened 4 years ago

MartinMuzatko commented 4 years ago

I noticed today, that using promisifyStream, the messages don't come one by one. This makes it hard to parse and work on the JSON strings of pull messages.

It looks like this when .split('\r\n')

[ '{"status":"Pulling from library/hello-world","id":"latest"}' ]
[
  '{"status":"Pulling fs layer","progressDetail":{},"id":"1b930d010525"}'
]
[
  '{"status":"Downloading","progressDetail":{"current":473,"total":977},"progress":"[========================\\u003e                          ]     473B/977B","id":"1b930d010525"}',
  '{"status":"Downloading","progressDetail":{"current":977,"total":977},"progress":"[==================================================\\u003e]     977B/977B","id":"1b930d010525"}',
  '{"status":"Verifying Checksum","progressDetail":{},"id":"1b930d010525"}',
  '{"status":"Download complete","progressDetail":{},"id":"1b930d010525"}'
]
[
  '{"status":"Extracting","progressDetail":{"current":977,"total":977},"progress":"[==================================================\\u003e]     977B/977B","id":"1b930d010525"}',
  '{"status":"Extracting","progressDetail":{"current":977,"total":977},"progress":"[==================================================\\u003e]     977B/977B","id":"1b930d010525"}'
]
[
  '{"status":"Pull complete","progressDetail":{},"id":"1b930d010525"}'
]
[
  '{"status":"Digest: sha256:9572f7cdcee8591948c2963463447a53466950b3fc15a247fcad1917ca215a2f"}'
]
[
  '{"status":"Status: Downloaded newer image for hello-world:latest"}'
]

Is there a way to make the fn in stream.on('data', fn) only receive single objects?

Thanks in advance!