Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("should accept string data", async () => {
const hash = new Hash("md5");
hash.update("");
const { buffer } = await hash.digest();
expect(fromArrayBuffer(buffer).toString("hex")).toBe(
"d41d8cd98f00b204e9800998ecf8427e"
);
});
function castSourceData(toCast: SourceData, encoding?: string): Buffer {
if (Buffer.isBuffer(toCast)) {
return toCast;
}
if (typeof toCast === "string") {
return fromString(toCast, encoding);
}
if (ArrayBuffer.isView(toCast)) {
return fromArrayBuffer(toCast.buffer, toCast.byteOffset, toCast.byteLength);
}
return fromArrayBuffer(toCast);
}
function castSourceData(toCast: SourceData, encoding?: string): Buffer {
if (Buffer.isBuffer(toCast)) {
return toCast;
}
if (typeof toCast === "string") {
return fromString(toCast, encoding);
}
if (ArrayBuffer.isView(toCast)) {
return fromArrayBuffer(toCast.buffer, toCast.byteOffset, toCast.byteLength);
}
return fromArrayBuffer(toCast);
}
export function toUtf8(input: Uint8Array): string {
return fromArrayBuffer(
input.buffer,
input.byteOffset,
input.byteLength
).toString("utf8");
}
export function toBase64(input: Uint8Array): string {
return fromArrayBuffer(
input.buffer,
input.byteOffset,
input.byteLength
).toString("base64");
}