apocas / docker-modem

Docker Remote API network stack driver.
Apache License 2.0
234 stars 112 forks source link

Return a buffer instead of a chunked string #97

Closed bchavet closed 6 years ago

bchavet commented 6 years ago

I ran into this problem when trying to get the logs from a container. The string I got back was not parseable. The problem is that converting a Buffer that contains the Docker stream control headers gets mangled in such a way that it cannot be converted back for parsing.

For example, if Docker returns a chunk like this:

<Buffer 02 00 00 00 00 00 00 98 5b 54 ... >

Converting that to a string and back results in a Buffer that looks like this:

<Buffer 02 00 00 00 00 00 00 ef bf bd 5b 54 ... >

Notice the two extra bytes, making the header un-parseable. No combination of string encodings changes this, either.

This pull request proposes that instead of concatenating all of the chunks into a string, they are instead concatenated into a larger Buffer, so the end user can manipulate it however they see fit when the result is not valid JSON.

apocas commented 6 years ago

Really like this 👍

apocas commented 6 years ago

Will ping when published.