Node.js Stream readable.readableEncoding Property
Last Updated :
12 Oct, 2021
The readable.readableEncodin property in a readable Stream is utilized to get the property encoding of a stated readable stream. Moreover, you can set this property using readable.setEncoding() method.
Syntax:
readable.readableEncoding
Return Value: It returns the encoding used in the program.
Below examples illustrate the use of readable.readableEncoding property in Node.js:
Example 1:
const fs = require( "fs" );
const readable = fs.createReadStream( "input.text" );
readable.setEncoding( "base64" );
readable.on( 'readable' , () => {
let chunk;
while ( null !== (chunk = readable.read())) {
console.log(`read: ${chunk}`);
}
});
readable.readableEncoding;
|
Output:
read: aGVs
read: bG8=
Example 2:
const fs = require( "fs" );
const readable = fs.createReadStream( "input.text" );
readable.setEncoding( "hex" );
readable.on( 'readable' , () => {
let chunk;
while ( null !== (chunk = readable.read())) {
console.log(`read: ${chunk}`);
}
});
readable.readableEncoding;
|
Output:
read: 68656c6c6f
Reference: https://nodejs.org/api/stream.html#stream_readable_readableencoding.
Share your thoughts in the comments
Please Login to comment...