I make RESTAPI
call to an endpoint and I expect to receive .tar
contents. But what I received is
<Buffer 4d 4d 00 2a 00 00 00 08 00 13 01 00 00 03 00 00 00 01 01......
The method connectForTar
shows how I receive the response and how I handle it.
Is it possible to convert that hexa representation to tar
? I want to get the tar
contents out of it, please.
code:
connectForTar(options, body, onResult) {
const resCallback = (response) => {
if (response.statusCode < 200 || response.statusCode > 299) {
console.error(errorTag,"Did not get an OK from the server. Code:",response.statusCode);
console.error(errorTag,"Did not get an OK from the server. Msg:",response.statusMessage);
onResult(response.statusCode, null);
response.resume();
return;
}
let data = [];
let buffer = null;
response.on('data', (chunk) => {
data.push(chunk);
});
response.on('end', () => {
buffer = Buffer.concat(data);
console.info({msg:infoTag +' response ended',contents:buffer});
onResult(response.statusCode, buffer, null);
});
}
const req = https.request(options, resCallback);
req.write(JSON.stringify(body));
req.on('error', (err) => {
console.error(errorTag + "problem with request.e.:", err);
console.error(errorTag + "problem with request.e.stack:", err.stack);
});
req.end();
}
tar contents
Whoever's told you you're getting a TAR file has misled you.
Based on the first bytes, MM<nul>*
(4D 4D 00 2A
in hexadecimal), you have a big-endian TIFF file, not a TAR file. (In other words, it's hard to get TAR contents out of those bytes, since they're evidently not a TAR.)
Given that the file also mentions Mercator, I would wager it's a GeoTIFF file.