MCPcopy Create free account
hub / github.com/PageLeay/celestial-runtime / zeroPad

Function zeroPad

lib.commonjs/utils/data.js:139–155  ·  view source on GitHub ↗
(data, length, left)

Source from the content-addressed store, hash-verified

137}
138exports.stripZerosLeft = stripZerosLeft;
139function zeroPad(data, length, left) {
140 const bytes = getBytes(data);
141 (0, errors_js_1.assert)(length >= bytes.length, "padding exceeds data length", "BUFFER_OVERRUN", {
142 buffer: new Uint8Array(bytes),
143 length: length,
144 offset: length + 1
145 });
146 const result = new Uint8Array(length);
147 result.fill(0);
148 if (left) {
149 result.set(bytes, length - bytes.length);
150 }
151 else {
152 result.set(bytes, 0);
153 }
154 return hexlify(result);
155}
156/**
157 * Return the [[DataHexString]] of %%data%% padded on the **left**
158 * to %%length%% bytes.

Callers 2

zeroPadValueFunction · 0.70
zeroPadBytesFunction · 0.70

Calls 3

getBytesFunction · 0.70
hexlifyFunction · 0.70
setMethod · 0.45

Tested by

no test coverage detected