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

Function zeroPad

src.ts/utils/data.ts:154–171  ·  view source on GitHub ↗
(data: BytesLike, length: number, left: boolean)

Source from the content-addressed store, hash-verified

152}
153
154function zeroPad(data: BytesLike, length: number, left: boolean): string {
155 const bytes = getBytes(data);
156 assert(length >= bytes.length, "padding exceeds data length", "BUFFER_OVERRUN", {
157 buffer: new Uint8Array(bytes),
158 length: length,
159 offset: length + 1
160 });
161
162 const result = new Uint8Array(length);
163 result.fill(0);
164 if (left) {
165 result.set(bytes, length - bytes.length);
166 } else {
167 result.set(bytes, 0);
168 }
169
170 return hexlify(result);
171}
172
173/**
174 * Return the [[DataHexString]] of %%data%% padded on the **left**

Callers 2

zeroPadValueFunction · 0.70
zeroPadBytesFunction · 0.70

Calls 4

assertFunction · 0.90
getBytesFunction · 0.70
hexlifyFunction · 0.70
setMethod · 0.45

Tested by

no test coverage detected