MCPcopy Create free account
hub / github.com/NoteProtocol/NoteWallet / splitBufferIntoSegments

Function splitBufferIntoSegments

src/utils.ts:5–26  ·  view source on GitHub ↗
(
  buffer: Buffer,
  segmentSize = MAX_SCRIPT_ELEMENT_SIZE,
  maxSegments = MAX_DATA_SEGMENTS
)

Source from the content-addressed store, hash-verified

3import {MAX_DATA_SEGMENTS, MAX_SCRIPT_ELEMENT_SIZE} from "./constants";
4
5export function splitBufferIntoSegments(
6 buffer: Buffer,
7 segmentSize = MAX_SCRIPT_ELEMENT_SIZE,
8 maxSegments = MAX_DATA_SEGMENTS
9): Buffer[] {
10 if (buffer.length / segmentSize > maxSegments) {
11 throw new Error(
12 `Buffer size exceeds the maximum allowed number of segments (${maxSegments}).`
13 );
14 }
15
16 const segments: Buffer[] = [];
17 let i = 0;
18 while (i < buffer.length) {
19 const start = i;
20 const end = Math.min((i += segmentSize), buffer.length);
21 const segment = buffer.subarray(start, end);
22 segments.push(Buffer.from(segment));
23 }
24
25 return segments;
26}
27
28export function concatenateBuffers(buffers: Buffer[]): Buffer {
29 return Buffer.concat(buffers);

Callers 2

buildNoteScriptV2Function · 0.90
buildNotePayloadFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected