-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement "output.hashCharacters" option to define character set for …
…file hashes (#5371) * Add documentation * Add new hashing functions and update hashes The hashes changed due to how they are now encoded * Add new hashing functions in JavaScript * Implement new output.hashCharacters option
- Loading branch information
1 parent
63a91a6
commit 57277bf
Showing
476 changed files
with
852 additions
and
440 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
const { parse, xxhashBase64Url } = require('./wasm-node/bindings_wasm.js'); | ||
const { | ||
parse, | ||
xxhashBase64Url, | ||
xxhashBase36, | ||
xxhashBase16 | ||
} = require('./wasm-node/bindings_wasm.js'); | ||
|
||
exports.parse = parse; | ||
exports.parseAsync = async (code, allowReturnOutsideFunction, _signal) => | ||
parse(code, allowReturnOutsideFunction); | ||
exports.xxhashBase64Url = xxhashBase64Url; | ||
exports.xxhashBase36 = xxhashBase36; | ||
exports.xxhashBase16 = xxhashBase16; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
use base64::{engine::general_purpose, Engine as _}; | ||
use base_encode::to_string; | ||
use xxhash_rust::xxh3::xxh3_128; | ||
|
||
const CHARACTERS_BASE64: &[u8; 64] = | ||
b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; | ||
|
||
const CHARACTERS_BASE36: &[u8; 36] = b"abcdefghijklmnopqrstuvwxyz0123456789"; | ||
|
||
const CHARACTERS_BASE16: &[u8; 16] = b"abcdef0123456789"; | ||
|
||
pub fn xxhash_base64_url(input: &[u8]) -> String { | ||
let hash = xxh3_128(input).to_le_bytes(); | ||
general_purpose::URL_SAFE_NO_PAD.encode(hash) | ||
to_string(&xxh3_128(input).to_le_bytes(), 64, CHARACTERS_BASE64).unwrap() | ||
} | ||
|
||
pub fn xxhash_base36(input: &[u8]) -> String { | ||
to_string(&xxh3_128(input).to_le_bytes(), 36, CHARACTERS_BASE36).unwrap() | ||
} | ||
|
||
pub fn xxhash_base16(input: &[u8]) -> String { | ||
to_string(&xxh3_128(input).to_le_bytes(), 16, CHARACTERS_BASE16).unwrap() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,27 @@ | ||
import { xxhashBase64Url } from '../../native'; | ||
import { xxhashBase16, xxhashBase36, xxhashBase64Url } from '../../native'; | ||
import type { HashCharacters } from '../rollup/types'; | ||
|
||
let textEncoder: TextEncoder; | ||
export function getXxhash(input: string | Uint8Array) { | ||
let buffer: Uint8Array; | ||
|
||
export type GetHash = (input: string | Uint8Array) => string; | ||
|
||
export const getHash64: GetHash = input => xxhashBase64Url(ensureBuffer(input)); | ||
export const getHash36: GetHash = input => xxhashBase36(ensureBuffer(input)); | ||
export const getHash16: GetHash = input => xxhashBase16(ensureBuffer(input)); | ||
|
||
export const hasherByType: Record<HashCharacters, GetHash> = { | ||
base36: getHash36, | ||
base64: getHash64, | ||
hex: getHash16 | ||
}; | ||
|
||
function ensureBuffer(input: string | Uint8Array): Uint8Array { | ||
if (typeof input === 'string') { | ||
if (typeof Buffer === 'undefined') { | ||
textEncoder ??= new TextEncoder(); | ||
buffer = textEncoder.encode(input); | ||
} else { | ||
buffer = Buffer.from(input); | ||
return textEncoder.encode(input); | ||
} | ||
} else { | ||
buffer = input; | ||
return Buffer.from(input); | ||
} | ||
return xxhashBase64Url(buffer); | ||
return input; | ||
} |
Oops, something went wrong.