D
D
dhdfshs2018-09-25 12:44:21
JavaScript
dhdfshs, 2018-09-25 12:44:21

How to cut the data in a variable by the number of bytes?

In general, the question is not an easy one.
I'm using curl and don't want to disable headers.
Therefore, the response from the server comes in the form of a header + body. The
body can be either text or a picture or a binary.

Status Code:  200
Headers:  [ { result: { version: 'HTTP/1.1', code: 200, reason: 'OK' },
    Server: 'nginx',
    Date: 'Tue, 25 Sep 2018 09:16:20 GMT',
    'Content-Type': 'image/png',
    'Content-Length': '1727',
    Connection: 'close',
    'Last-Modified': 'Thu, 21 Dec 2017 23:49:29 GMT',
    ETag: '"5a3c4889-6bf"',
    Expires: 'Sat, 24 Nov 2018 09:16:20 GMT',
    'Cache-Control': 'public, max-age=5184000',
    'Access-Control-Allow-Origin': '*',
    'Accept-Ranges': 'bytes' } ]
Headers length:  1
Body length:  2061
METHOD:  GET
Header length: 371

Strange things are happening here.
In theory, Body length subtracting 'Content-Length' should result in Header length:
But damn it
Apparently the length function in javascript does not cope with the task of calculating the length in baht.
There is a variable It stores the server header and data, possibly binary. How to find the size of the body variable in bytes? How to cut body from the beginning to the required number of bytes? I have already checked the functions substring, length - do not work.
var body = 'header+body';

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
grinat, 2018-09-26
@grinat

https://developer.mozilla.org/ru/docs/Web/API/Blob
https://developer.mozilla.org/ru/docs/Web/API/XMLH...
For a node: https://nodejs. org/api/buffer.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question