Buffer is a temporary memory storage which stores the data when it is being moved from one place to another, it’s like the array of integers.
The Buffer.slice() method returns a new Buffer that points to the same memory location as that of the input Buffer with only the cropped elements.
buffer.slice( start, end )
Parameters: This method accepts two parameters as mentioned above and described below:
- start: It refers to the starting index from which the elements of input buffer will be copied to the output buffer.
- end: It refers to the ending index till which the elements of input buffer will be copied to the output buffer. (end index is not included in the count while slicing the buffer)
Return Value: It returns a buffer containing the altered buffer.
Note: Default value of start and end indexes are 0 and buffer.length respectively. Negative indexes start from end of the array.
Below examples illustrate the use of Buffer.slice() Method in Node.js:
Sliced Buffer is: Geek
Geek One Geek Two
Note: The above program will compile and run by using the
node fileName.js command.
- Nodejs | Automatic restart NodeJs server with nodemon
- Nodejs | DNS
- Nodejs | Jimp
- Nodejs | DNS | setServers()
- Web-Socket in NodeJS
- Nodejs | GM blur() Function
- Nodejs | GM charcoal() Function
- Dockerizing a simple Nodejs app
- Nodejs | GM sharpen() Function
- Difference between NodeJS and AngularJS
- Encrypting Data in NodeJS
- Nodejs | Web Crawling using Cheerio
- Cowsay in Nodejs using Requests library
- Signup Form Using Nodejs and MongoDB
- NodeJs - Handling invalid routes
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.