Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@
"vitest": "^4.1.4",
"yargs": "^18.0.0"
},
"dependencies": {
"base64-js": "^1.2.0"
},
"files": [
".",
"dist"
Expand Down
3 changes: 1 addition & 2 deletions src/JsHistogram.encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
* and released to the public domain, as explained at
* http://creativecommons.org/publicdomain/zero/1.0/
*/
// @ts-ignore
import * as base64 from "base64-js";
import * as base64 from "./base64";
import { JsHistogram } from "./JsHistogram";
import ByteBuffer from "./ByteBuffer";
import { BitBucketSize } from "./Histogram";
Expand Down
32 changes: 32 additions & 0 deletions src/base64.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Minimal base64 codec replacing the `base64-js` dependency.
*
* Relies on the standard `btoa`/`atob` globals, available in Node >= 16 (this
* project requires >= 22) and all modern browsers. Produces and consumes
* standard base64 (`+`/`/`), matching what HdrHistogram encodes.
*/

// Uint8Array -> standard base64 string.
// Build the binary string in chunks so large inputs (e.g. the WASM blob) don't
// overflow String.fromCharCode's argument-stack limit.
export function fromByteArray(bytes: Uint8Array): string {
const CHUNK = 0x8000;
let binary = "";
for (let i = 0; i < bytes.length; i += CHUNK) {
binary += String.fromCharCode.apply(
null,
bytes.subarray(i, i + CHUNK) as unknown as number[]
);
}
return btoa(binary);
}

// standard base64 string -> Uint8Array.
export function toByteArray(b64: string): Uint8Array {
const binary = atob(b64);
const bytes = new Uint8Array(binary.length);
for (let i = 0; i < binary.length; i++) {
bytes[i] = binary.charCodeAt(i);
}
return bytes;
}
3 changes: 1 addition & 2 deletions src/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import ByteBuffer from "./ByteBuffer";
import Histogram from "./Histogram";
import { WasmHistogram } from "./wasm";

// @ts-ignore
import * as base64 from "base64-js";
import * as base64 from "./base64";
import { inflate, deflate } from "./JsHistogram.encoding";

const V2CompressedEncodingCookieBase = 0x1c849304;
Expand Down
3 changes: 1 addition & 2 deletions src/wasm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import Histogram, {
toSummary,
HistogramSummary
} from "../Histogram";
// @ts-ignore
import * as base64 from "base64-js";
import * as base64 from "../base64";
import { inflate } from "../JsHistogram.encoding";
import { BuildRequest } from "../HistogramBuilder";

Expand Down
Loading