I need to know the encoding of a node stream for which I am using detect-character-encoding module. But the problem is that I can only read encodings of a buffer and not a stream due to which I have to do something like this:
FileStream.on('data', (chunk) => {
console.log(chunk)
const charsetMatch = detectCharacterEncoding(chunk)
console.log(charsetMatch)
})
Knowing stream encoding comes at the cost of losing a chunk of data, which is required later in the code flow. Is there a way possible in which I can just peek at chunk know its encoding and not lose the chunk and data?