Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7036755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:27:43+00:00 2026-05-28T01:27:43+00:00

I am kind of confused by the Buffer.copy api in node.js in the meaning

  • 0

I am kind of confused by the Buffer.copy api in node.js in the meaning of the buffer indexes. I was expecting it to be similar to memcpy in C/Unix but it does not seem to be the case

As per the API doc and an example provided in http://nodejs.org/docs/latest/api/buffers.html#buffer.copy

buffer.copy(targetBuffer, [targetStart], [sourceStart], [sourceEnd]) 

means the targetStart is not the index into targetBuffer with index starting with 0, same is the case with sourceStart. Rather the indexes seem to start with 1 and not 0. The most confusing is the sourceEnd. From the example looks like it the bytes before before the sourceEnd byte are copied, then how would the last byte be copied

The example in node.js doc is
Example: build two Buffers, then copy buf1 from byte 16 through byte 19 into buf2, starting at the 8th byte in buf2.
For this the statement is

buf1 = new Buffer(26);
buf2 = new Buffer(26);
buf1.copy(buf2, 8, 16, 20);

What if I wanted to copy till the 26th byte, do I need to specify 27 as sourceEnd ? looks very odd that I need to provide a value greater than the length of the source buffer

Can someone provide a clear explanation as to why node.js selected this kind of behaviour rather than remain similar to memcpy ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:27:44+00:00Added an answer on May 28, 2026 at 1:27 am

    The reason for choosing these (potentially confusing) index conventions likely has to do with the precedent set by core JavaScript functions such as String.slice.

    Remember, node.js is based on JavaScript, not C/POSIX after all =)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am kind of confused by one question: Under what cirumstances does the MS
It might look silly, but I'm kind of confused about this now. Why this
I want to create a desktop like app, but I'm kind of confused as
I'm kind of confused by ofstream. ofstream inherited from ostream. And it also inherited
I'm kind of confused. I would put all the HTML for the menu in
I'm kind of confused about reserved words in Ruby. The Ruby Programming Language, co-authored
I have always been kind of confused by threads, and my class right now
Please help me out here because im getting kind of confused.. I have a
I'm a noob in python. I'm kind of confused about how the python unit
i am kind of confused why python add some additional decimal number in this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.