S
S
SagePtr2019-11-07 19:28:57
Node.js
SagePtr, 2019-11-07 19:28:57

[Nodejs] Is it safe to cut in parts from the buffer?

Let's say something like this:

let buffer = Buffer.from(..........);
  while (... какое-то условие ...) {
    let bufferPart = buffer.slice(0, N); // отрезали первые N байт буфера
    doSomething(bufferPart); // сделали что-то с этим фрагментом
    buffer = buffer.slice(N, buffer.length); // укоротили буфер, выкинув начальные N байт
  }

With this approach, the original buffer will live until the references to each slice to it run out (even if there are no more references to the original), after which it will be marked for deletion by the garbage collector?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question