Node.js readStream.isRaw Property

The readStream.isRaw property is an inbuilt application programming interface of class ReadStream within tty module which is used to check if the read stream object is currently configured to operate as a raw device or not.

Syntax:

const status = ReadStream.isRaw;

Return Value: This property returns true if and only if the read stream object is currently configured to operate as a raw device.

Example 1: Filename: index.js

filter_none

edit
close

play_arrow

link
brightness_4
code

// Node.js program to demonstrate the
// readStream.isRaw property
  
// Importing dgram module
var dgram = require('dgram');
  
// Creating and initializing client
// and server socket
var client = dgram.createSocket("udp4");
var server = dgram.createSocket("udp4");
  
// Catching the message event
server.on("message", function (msg) {
  
    // Creating and initializing a
    // ReadStream object
    let ReadStream = process.stdin;
  
    // Checking if it is configured or
    // not by using isRaw() method
    const status = ReadStream.isRaw;
  
    // Displaying the result
    if (status) {
        process.stdout.write(msg 
            + "configured" + "\n");
    } else {
        process.stdout.write(msg 
            + "not configured" + "\n");
    }
  
    // Exiting process
    process.exit();
})
  
// Binding server with port
.bind(1234, () => {
});
  
// Client sending message to server
client.send("It is ", 0, 7, 1234, "localhost");

chevron_right


Output:



It is not configured

Example 2: Filename: index.js

filter_none

edit
close

play_arrow

link
brightness_4
code

// Node.js program to demonstrate the
// readStream.isRaw property
  
// Creating and initializing a 
// ReadStream object
let ReadStream = process.stdin;
  
// Setting the read stream Raw mode
// by using setRawMode() method
ReadStream.setRawMode(true);
  
// Checking if it is configured or not 
// by using isRaw() method
const status = ReadStream.isRaw;
  
// Displaying the result
if(status) {
   console.log("It is configured");
} else {
   console.log("it is not configured");
}

chevron_right


Run the index.js file using the following command:

node index.js

Output:

It is configured

Reference: https://nodejs.org/dist/latest-v12.x/docs/api/tty.html#tty_readstream_israw




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.