What is a buffer in Node.js?

后端 未结 3 1071
离开以前
离开以前 2021-02-02 06:34

As you can read in the Node.js documentation on the Buffer class, a buffer

is similar to an array of integers but corresponds to a raw memory allocation o

相关标签:
3条回答
  • 2021-02-02 07:15

    BUFFER is a temporary holding spot for data being moved from one place to another.

    In order to understand what is Buffer, we need to know how a computer will process things. See the chart below.

    The concept is like if you are watching a Youtube Video, you can start to watch a video without downloading the whole video. If your internet speed is too slow, you would see "buffering", that means the computer is trying to collect data in order for you to keep watching that video.

    0 讨论(0)
  • 2021-02-02 07:20

    Explanation from http://nodejitsu.com/...

    Buffers are instances of the Buffer class in node, which is designed to handle raw binary data. Each buffer corresponds to some raw memory allocated outside V8. Buffers act somewhat like arrays of integers, but aren't resizable and have a whole bunch of methods specifically for binary data. In addition, the "integers" in a buffer each represent a byte and so are limited to values from 0 to 255 (2^8 - 1), inclusive.

    Read more: Buffers in Node.js

    0 讨论(0)
  • 2021-02-02 07:31

    A Buffer is a chunk of memory, just like you would have it in C/C++. You can interpret this memory as an array of integer or floating point numbers of various lengths, or as a binary string. Unlike higher-level data structures like arrays, a buffer is not resizable.

    It corresponds roughly to:

    • char* or char[] in C/C++
    • byte[] in Java
    • A mutable bytes or a non-resizable bytearray in Python
    • Strings in php if they were mutable
    0 讨论(0)
提交回复
热议问题