What's the difference between a byte stream and a byte string?

82 views Asked by At

From the DocuSign documentation on documents, "when you add a document file to an envelope, the DocuSign platform converts it to PDF and stores it as base64-encoded ASCII" and then in REST API doc for getDocument, "by default, the response is the PDF file as a byte stream... By using the Content-Transfer-Encoding header in the request, you can obtain the PDF file encoded in base64." (emphasis mine)

This is what I understand thus far:

  • When you download a document from DocuSign, you've to decode it back to its binary representation either with base64 or "byte stream" in order to save it to disk or provide it to another service that expects a Buffer. In NodeJS, which is how I'm interacting with DocuSign, this looks as follows:

    • Buffer.from(pdfContent, "base64"), assuming you downloaded the base64-encoded PDF.
    • Buffer.from(pdfContent, "binary") ([binary is an alias to latin11), assuming you downloaded the "byte stream" PDF.
  • When you download a document from DocuSign, you download the entire file at once and therefore it's not being streamed. In both cases, you're simply getting a whole string from DocuSign, not chunks of bytes.

The use of the term "byte stream" is what confuses me here because DocuSign isn't streaming the file (e.g., as I understand it streaming implies consuming from/writing to a resource chunk by chunk instead of as a whole). Assuming I'm correct, then a better term is byte string. Hence my questions:

  • Is the term byte stream being used interchangeably with byte string here?
  • At least in NodeJS, you need to decode the "byte stream" with binary (or latin1). Thus, is DocuSign using "byte stream" as the term for "binary code that must be decoded using the character encoding latin1"?

  1. From NodeJS Buffer docs: "'binary': Alias for 'latin1'. The name of this encoding can be very misleading, as all of the encodings listed here convert between strings and binary data. For converting between strings and Buffers, typically 'utf8' is the right choice."
1

There are 1 answers

2
Larry K On

The response is the file as a byte string, it is not a JSON response.

You are correct, the right terminology is byte string, not byte stream. We'll get the docs updated.

If you download as a byte string, it won't be encoded. It will be in binary. If your client can't handle that, then download with base64 encoding and then decode to binary.