I'm using dockerode and a read stream using the cat command to resolve the contents of a file, however I'm also getting encoded characters that I assume are for defining a file format. I know I could remove them by removing x characters from the beginning of the string although I feel theres probably a better safer way of properly reading the file.
container.exec({
Cmd: ['sh', '-c', 'cat /myfile.json'],
AttachStdin: true,
AttachStdout: true,
AttachStderr: true,
}, (err, exec) => {
exec.start({
stdin: true
}, (err, stream) => {
if (err) {
return res.status(500).json({
success: false,
message: 'Error reading file.',
});
}
let data = '';
stream.on('data', (chunk) => {
data += chunk;
});
stream.on('end', () => {
return res.status(200).json({
success: true,
data
});
});
});
});
The original contents of the file are []
, however it returns \x01\x00\x00\x00\x00\x00\x00\x02[]
How can I only get the contents []
without using something like a substring method?