Skip to content
Related Articles

Related Articles

Improve Article
Node.js v8.Serializer.writeRawBytes() Method
  • Last Updated : 22 Jul, 2020

The v8.Serializer.writeRawBytes() method is an inbuilt application programming interface of the v8.Serializer module which is used to write a raw buffer data to the internal buffer. For use inside of custom serializer._writeHostObject().

Syntax:

v8.Serializer.writeRawBytes( Buffer );

Parameters: This method accepts single parameter as mentioned above and described below:

  • Buffer: It is a required parameter, refers to a buffer/typed array/data view to be written to the internal buffer.

Return Value: This method does not return anything but writes raw buffer data to the internal buffer.

Below examples illustrate the use of v8.Serializer.writeRawBytes() method in Node.js.



Example 1: Filename: index.js




// Accessing v8 module
const v8 = require('v8');
const serializer = new v8.Serializer();
  
// Calling v8.serializer.writeRawBytes() 
serializer.writeRawBytes(v8.serialize(5783));
console.log(serializer.releaseBuffer());

Run index.js file using the following command:

node index.js

Output:

<Buffer ff 0d 49 ae 5a>

Example 2: Filename: index.js




// Accessing v8 module
const v8 = require('v8');
const serializer = new v8.Serializer();
  
// Calling v8.serializer.writeRawBytes() 
console.log(serializer.releaseBuffer());
  
// User defined Function
function writeRawData(data) {
    serializer.writeRawBytes(v8.serialize(data));
    console.log("" + serializer.releaseBuffer());
}
  
// Function Call
writeRawData("GeeksforGeeks");

Run index.js file using the following command:

node index.js

Output:

<Buffer >
GeeksforGeeks

Reference: https://nodejs.org/api/v8.html#v8_serializer_writerawbytes_buffer

My Personal Notes arrow_drop_up
Recommended Articles
Page :