Astro+Directus(Visual-Editing)+Snipcart Test-Stack
This commit is contained in:
commit
1459e99cb0
10119 files changed
+1499318
No files matched your search
+25
@@ -0,0 +1,25 @@
|
||||
The MIT License (MIT)
|
||||
=====================
|
||||
|
||||
Copyright © 2017 Michael Jungo
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the “Software”), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
+401
@@ -0,0 +1,401 @@
|
||||
# xxhash-wasm
|
||||
|
||||
[![Node.js][actions-nodejs-badge]][actions-nodejs-link]
|
||||
[![npm][npm-badge]][npm-link]
|
||||
|
||||
A WebAssembly implementation of [xxHash][xxhash], a fast non-cryptographic hash
|
||||
algorithm. It can be called seamlessly from JavaScript. You can use it like any
|
||||
other JavaScript library but still get the benefits of WebAssembly, no special
|
||||
setup needed.
|
||||
|
||||
## Table of Contents
|
||||
|
||||
<!-- vim-markdown-toc GFM -->
|
||||
|
||||
* [Installation](#installation)
|
||||
* [From npm](#from-npm)
|
||||
* [From Unpkg](#from-unpkg)
|
||||
* [ES Modules](#es-modules)
|
||||
* [UMD build](#umd-build)
|
||||
* [Cloudflare Workers](#cloudflare-workers)
|
||||
* [Usage](#usage)
|
||||
* [Streaming Example](#streaming-example)
|
||||
* [Node](#node)
|
||||
* [Performance](#performance)
|
||||
* [Engine Requirements](#engine-requirements)
|
||||
* [API](#api)
|
||||
* [h32](#h32)
|
||||
* [h64](#h64)
|
||||
* [Streaming](#streaming)
|
||||
* [Comparison to xxhashjs](#comparison-to-xxhashjs)
|
||||
* [Benchmarks](#benchmarks)
|
||||
* [Bundle size](#bundle-size)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
## Installation
|
||||
|
||||
### From npm
|
||||
|
||||
```sh
|
||||
npm install --save xxhash-wasm
|
||||
```
|
||||
|
||||
Or with Yarn:
|
||||
|
||||
```sh
|
||||
yarn add xxhash-wasm
|
||||
```
|
||||
|
||||
### From [Unpkg][unpkg]
|
||||
|
||||
#### ES Modules
|
||||
|
||||
```html
|
||||
<script type="module">
|
||||
import xxhash from "https://unpkg.com/xxhash-wasm/esm/xxhash-wasm.js";
|
||||
</script>
|
||||
```
|
||||
|
||||
#### UMD build
|
||||
|
||||
```html
|
||||
<script src="https://unpkg.com/xxhash-wasm/umd/xxhash-wasm.js"></script>
|
||||
```
|
||||
|
||||
The global `xxhash` will be available.
|
||||
|
||||
### Cloudflare Workers
|
||||
|
||||
If you are using [Cloudflare Workers](https://developers.cloudflare.com/workers/) (workerd) you can use the installed
|
||||
npm package as is. The `xxhash-wasm` package is compatible with Cloudflare Workers.
|
||||
|
||||
```javascript
|
||||
import xxhash from "xxhash-wasm";
|
||||
```
|
||||
|
||||
Importing it will pick the correct file base on the [conditional
|
||||
import](https://developers.cloudflare.com/workers/wrangler/bundling/#conditional-exports)
|
||||
from the package.json.
|
||||
|
||||
## Usage
|
||||
|
||||
The WebAssembly is contained in the JavaScript bundle, so you don't need to
|
||||
manually fetch it and create a new WebAssembly instance.
|
||||
|
||||
```javascript
|
||||
import xxhash from "xxhash-wasm";
|
||||
|
||||
// Creates the WebAssembly instance.
|
||||
xxhash().then(hasher => {
|
||||
const input = "The string that is being hashed";
|
||||
|
||||
// 32-bit version
|
||||
hasher.h32(input); // 3998627172 (decimal representation)
|
||||
// For convenience, get hash as string of its zero-padded hex representation
|
||||
hasher.h32ToString(input); // "ee563564"
|
||||
|
||||
// 64-bit version
|
||||
hasher.h64(input); // 5776724552493396044n (BigInt)
|
||||
// For convenience, get hash as string of its zero-padded hex representation
|
||||
hasher.h64ToString(input); // "502b0c5fc4a5704c"
|
||||
});
|
||||
```
|
||||
|
||||
Or with `async`/`await` and destructuring:
|
||||
|
||||
```javascript
|
||||
// Creates the WebAssembly instance.
|
||||
const { h32, h64 } = await xxhash();
|
||||
|
||||
const input = "The string that is being hashed";
|
||||
// 32-bit version
|
||||
h32(input); // 3998627172 (decimal representation)
|
||||
// 64-bit version
|
||||
h64(input); // 5776724552493396044n (BigInt)
|
||||
```
|
||||
|
||||
### Streaming Example
|
||||
|
||||
`xxhash-wasm` supports a `crypto`-like streaming api, useful for avoiding memory
|
||||
consumption when hashing large amounts of data:
|
||||
|
||||
```javascript
|
||||
const { create32, create64 } = await xxhash();
|
||||
|
||||
// 32-bit version
|
||||
create32()
|
||||
.update("some data")
|
||||
// update accepts either a string or Uint8Array
|
||||
.update(Uint8Array.from([1, 2, 3]))
|
||||
.digest(); // 955607085
|
||||
|
||||
// 64-bit version
|
||||
create64()
|
||||
.update("some data")
|
||||
// update accepts either a string or Uint8Array
|
||||
.update(Uint8Array.from([1, 2, 3]))
|
||||
.digest(); // 883044157688673477n
|
||||
```
|
||||
|
||||
### Node
|
||||
|
||||
It doesn't matter whether you are using CommonJS or ES Modules in Node
|
||||
(e.g. with `"type": "module"` in `package.json` or using the explicit file
|
||||
extensions `.cjs` or `.mjs` respectively), importing `xxhash-wasm` will always
|
||||
load the corresponding module, as both bundles are provided and specified in
|
||||
the `exports` field of its `package.json`, therefore the appropriate one will
|
||||
automatically be selected.
|
||||
|
||||
**Using ES Modules**
|
||||
|
||||
```javascript
|
||||
import xxhash from "xxhash-wasm";
|
||||
```
|
||||
|
||||
**Using CommonJS**
|
||||
|
||||
```javascript
|
||||
const xxhash = require("xxhash-wasm");
|
||||
```
|
||||
|
||||
## Performance
|
||||
|
||||
For performance sensitive applications, `xxhash-wasm` provides the `h**` and
|
||||
`h**Raw` APIs, which return raw numeric hash results rather than zero-padded hex
|
||||
strings. The overhead of the string conversion in the `h**ToString` APIs can be
|
||||
as much as 20% of overall runtime when hashing small byte-size inputs, and the
|
||||
string result is often inconsequential (for example when simply checking if the
|
||||
the resulting hashes are the same). When necessary, getting a zero-padded hex
|
||||
string from the provided `number` or [`BigInt`][bigint-mdn] results is easily
|
||||
achieved via `result.toString(16).padStart(16, "0")` and the `h**ToString` APIs
|
||||
are purely for convenience.
|
||||
|
||||
The `h**`, `h**ToString`, and streaming APIs make use of
|
||||
[`TextEncoder.encodeInto`][textencoder-encodeinto-mdn] to directly encode
|
||||
strings as a stream of UTF-8 bytes into the WebAssembly memory buffer, meaning
|
||||
that for string-hashing purposes, these APIs will be significantly faster than
|
||||
converting the string to bytes externally and using the `Raw` API. That said,
|
||||
for large strings it may be beneficial to consider the streaming API or another
|
||||
approach to encoding, as `encodeInto` is forced to allocate 3-times the string
|
||||
length to account for the chance the input string contains high-byte-count
|
||||
code units.
|
||||
|
||||
*If possible, defer the encoding of the string to the hashing, unless you need
|
||||
to use the encoded string (bytes) for other purposes as well, or you are
|
||||
creating the bytes differently (e.g. different encoding), in which case it's
|
||||
much more efficient to use the `h**Raw` APIs instead of having to unnecessarily
|
||||
convert them to a string first.*
|
||||
|
||||
### Engine Requirements
|
||||
|
||||
In an effort to make this library as performant as possible, it uses several
|
||||
recent additions to browsers, Node and the WebAssembly specification.
|
||||
Notably, these include:
|
||||
|
||||
1. [`BigInt`][bigint-mdn] support in WebAssembly
|
||||
2. Bulk memory operations in WebAssembly
|
||||
3. [`TextEncoder.encodeInto`][textencoder-encodeinto-mdn]
|
||||
|
||||
Taking all of these requirements into account, `xxhash-wasm` should be
|
||||
compatible with:
|
||||
|
||||
* Chrome >= 85
|
||||
* Edge >= 79
|
||||
* Firefox >= 79
|
||||
* Safari >= 15.0
|
||||
* Node >= 15.0
|
||||
|
||||
If support for an older engine is required, `xxhash-wasm@0.4.2` is available
|
||||
with much broader engine support, but 3-4x slower hashing performance.
|
||||
|
||||
## API
|
||||
|
||||
```js
|
||||
const {
|
||||
h32,
|
||||
h32ToString,
|
||||
h32Raw,
|
||||
create32,
|
||||
h64,
|
||||
h64ToString,
|
||||
h64Raw,
|
||||
create64,
|
||||
} = await xxhash();
|
||||
```
|
||||
|
||||
Create a WebAssembly instance.
|
||||
|
||||
### h32
|
||||
|
||||
```typescript
|
||||
h32(input: string, [seed: u32]): number
|
||||
```
|
||||
|
||||
Generate a 32-bit hash of the UTF-8 encoded bytes of `input`. The optional
|
||||
`seed` is a `u32` and any number greater than the maximum (`0xffffffff`) is
|
||||
wrapped, which means that `0xffffffff + 1 = 0`.
|
||||
|
||||
Returns a `u32` `number` containing the hash value.
|
||||
|
||||
```typescript
|
||||
h32ToString(input: string, [seed: u32]): string
|
||||
```
|
||||
|
||||
Same as `h32`, but returning a zero-padded hex string.
|
||||
|
||||
```typescript
|
||||
h32Raw(input: Uint8Array, [seed: u32]): number
|
||||
```
|
||||
|
||||
Same as `h32` but with a `Uint8Array` as input instead of a `string`.
|
||||
|
||||
### h64
|
||||
|
||||
```typescript
|
||||
h64(input: string, [seed: bigint]): bigint
|
||||
```
|
||||
|
||||
Generate a 64-bit hash of the UTF-8 encoded bytes of `input`. The optional
|
||||
`seed` is a `u64` provided as a [BigInt][bigint-mdn].
|
||||
|
||||
Returns a `u64` `bigint` containing the hash value.
|
||||
|
||||
```typescript
|
||||
h64ToString(input: string, [seed: bigint]): string
|
||||
```
|
||||
|
||||
Same as `h64`, but returning a zero-padded hex string.
|
||||
|
||||
```typescript
|
||||
h64Raw(input: Uint8Array, [seed: bigint]): bigint
|
||||
```
|
||||
|
||||
Same as `h64` but with a `Uint8Array` as input instead of a `string`.
|
||||
|
||||
### Streaming
|
||||
|
||||
```typescript
|
||||
type XXHash<T> {
|
||||
update(input: string | Uint8Array): XXHash<T>;
|
||||
digest(): T
|
||||
}
|
||||
```
|
||||
|
||||
The streaming API mirrors Node's built-in `crypto.createHash`, providing
|
||||
`update` and `digest` methods to add data to the hash and compute the final hash
|
||||
value, respectively.
|
||||
|
||||
```typescript
|
||||
create32([seed: number]): XXHash<number>
|
||||
```
|
||||
|
||||
Create a 32-bit hash for streaming applications.
|
||||
|
||||
```typescript
|
||||
create64([seed: bigint]): XXHash<bigint>
|
||||
```
|
||||
|
||||
Create a 64-bit hash for streaming applications.
|
||||
|
||||
## Comparison to [xxhashjs][xxhashjs]
|
||||
|
||||
[`xxhashjs`][xxhashjs] is implemented in pure JavaScript and because JavaScript
|
||||
is lacking support for 64-bit integers, it uses a workaround with
|
||||
[`cuint`][cuint]. Not only is that a big performance hit, but it also increases
|
||||
the bundle size by quite a bit when it's used in the browser.
|
||||
|
||||
This library (`xxhash-wasm`) has the big advantage that WebAssembly supports
|
||||
`u64` and also some instructions (e.g. `rotl`), which would otherwise have
|
||||
to be emulated. However, The downside is that you have to initialise
|
||||
a WebAssembly instance, which takes a little over 2ms in Node and about 1ms in
|
||||
the browser. But once the instance is created, it can be used without any
|
||||
further overhead. For the benchmarks below, the instantiation is done before the
|
||||
benchmark and therefore it's excluded from the results, since it wouldn't make
|
||||
sense to always create a new WebAssembly instance.
|
||||
|
||||
### Benchmarks
|
||||
|
||||
Benchmarks are using [Benchmark.js][benchmarkjs] with random strings of
|
||||
different lengths. *Higher is better*
|
||||
|
||||
| String length | xxhashjs 32-bit | xxhashjs 64-bit | xxhash-wasm 32-bit | xxhash-wasm 64-bit |
|
||||
| ------------------------: | ------------------ | ------------------ | ----------------------- | ----------------------- |
|
||||
| 1 byte | 513,517 ops/sec | 11,896 ops/sec | ***5,752,446 ops/sec*** | 4,438,501 ops/sec |
|
||||
| 10 bytes | 552,133 ops/sec | 12,953 ops/sec | ***6,240,640 ops/sec*** | 4,855,340 ops/sec |
|
||||
| 100 bytes | 425,277 ops/sec | 10,838 ops/sec | ***5,470,011 ops/sec*** | 4,314,904 ops/sec |
|
||||
| 1,000 bytes | 102,165 ops/sec | 6,697 ops/sec | 3,283,526 ops/sec | ***3,332,556 ops/sec*** |
|
||||
| 10,000 bytes | 13,010 ops/sec | 1,452 ops/sec | 589,068 ops/sec | ***940,350 ops/sec*** |
|
||||
| 100,000 bytes | 477 ops/sec | 146 ops/sec | 61,824 ops/sec | ***98,959 ops/sec*** |
|
||||
| 1,000,000 bytes | 36.40 ops/sec | 12.93 ops/sec | 5,122 ops/sec | ***8,632 ops/sec*** |
|
||||
| 10,000,000 bytes | 3.12 ops/sec | 1.19 ops/sec | 326 ops/sec | ***444 ops/sec*** |
|
||||
| 100,000,000 bytes | 0.31 ops/sec | 0.13 ops/sec | 27.84 ops/sec | ***34.56 ops/sec*** |
|
||||
|
||||
`xxhash-wasm` outperforms `xxhashjs` significantly, the 32-bit is up to 90 times
|
||||
faster (generally increases as the size of the input grows), and the 64-bit is
|
||||
up to 350 times faster (generally increases as the size of the input grows).
|
||||
|
||||
The 64-bit version is the faster algorithm but there is a small degree of
|
||||
overhead involved in using BigInts, and so it retains a performance advantage
|
||||
over all lengths over xxhashjs and the 32-bit algorithm above ~1000 bytes.
|
||||
|
||||
`xxhash-wasm` also significantly outperforms Node's built-in hash algorithms,
|
||||
making it suitable for use in a wide variety of situations, where
|
||||
non-cryptographic hashes are acceptable. Benchmarks from an x64 MacBook Pro
|
||||
running Node 17.3:
|
||||
|
||||
| String length | Node `crypto` md5 | Node `crypto` sha1 | xxhash-wasm 64-bit |
|
||||
| ------------------------: | ------------------ | ------------------ | ----------------------- |
|
||||
| 1 byte | 342,924 ops/sec | 352,825 ops/sec | ***4,438,501 ops/sec*** |
|
||||
| 10 bytes | 356,596 ops/sec | 352,209 ops/sec | ***4,855,340 ops/sec*** |
|
||||
| 100 bytes | 354,898 ops/sec | 355,024 ops/sec | ***4,314,904 ops/sec*** |
|
||||
| 1,000 bytes | 249,242 ops/sec | 271,383 ops/sec | ***3,332,556 ops/sec*** |
|
||||
| 10,000 bytes | 62,896 ops/sec | 80,986 ops/sec | ***940,350 ops/sec*** |
|
||||
| 100,000 bytes | 7,316 ops/sec | 10,198 ops/sec | ***98,959 ops/sec*** |
|
||||
| 1,000,000 bytes | 698 ops/sec | 966 ops/sec | ***8,632 ops/sec*** |
|
||||
| 10,000,000 bytes | 58.98 ops/sec | 79.78 ops/sec | ***444 ops/sec*** |
|
||||
| 100,000,000 bytes | 6.30 ops/sec | 8.20 ops/sec | ***34.56 ops/sec*** |
|
||||
|
||||
If suitable for your use case, the `Raw` API offers significant throughput
|
||||
improvements over the string-hashing API, particularly for smaller inputs,
|
||||
assuming that you have access to the `Uint8Array` already (see also the
|
||||
[Performance section](#performance)):
|
||||
|
||||
| String length | xxhash-wasm 64-bit Raw | xxhash-wasm 64-bit |
|
||||
| ------------------------: | ----------------------- | ------------------- |
|
||||
| 1 byte | ***9,342,811 ops/sec*** | 4,438,501 ops/sec |
|
||||
| 10 bytes | ***9,668,989 ops/sec*** | 4,855,340 ops/sec |
|
||||
| 100 bytes | ***8,775,845 ops/sec*** | 4,314,904 ops/sec |
|
||||
| 1,000 bytes | ***5,541,403 ops/sec*** | 3,332,556 ops/sec |
|
||||
| 10,000 bytes | ***1,079,866 ops/sec*** | 940,350 ops/sec |
|
||||
| 100,000 bytes | ***113,350 ops/sec*** | 98,959 ops/sec |
|
||||
| 1,000,000 bytes | ***9,779 ops/sec*** | 8,632 ops/sec |
|
||||
| 10,000,000 bytes | ***563 ops/sec*** | 444 ops/sec |
|
||||
| 100,000,000 bytes | ***43.77 ops/sec*** | 34.56 ops/sec |
|
||||
|
||||
### Bundle size
|
||||
|
||||
Both libraries can be used in the browser and they provide a UMD bundle. The
|
||||
bundles are self-contained, that means they can be included and used without
|
||||
having to add any other dependencies. The table shows the bundle size of the
|
||||
minified versions. *Lower is better*.
|
||||
|
||||
| | xxhashjs | xxhash-wasm |
|
||||
| -------------- | ---------- | ------------- |
|
||||
| Bundle size | 41.5kB | ***11.4kB*** |
|
||||
| Gzipped Size | 10.3kB | ***2.3kB*** |
|
||||
|
||||
[actions-nodejs-badge]: https://github.com/jungomi/xxhash-wasm/actions/workflows/nodejs.yml/badge.svg
|
||||
[actions-nodejs-link]: https://github.com/jungomi/xxhash-wasm/actions/workflows/nodejs.yml
|
||||
[benchmarkjs]: https://benchmarkjs.com/
|
||||
[bigint-mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt
|
||||
[cuint]: https://github.com/pierrec/js-cuint
|
||||
[npm-badge]: https://img.shields.io/npm/v/xxhash-wasm.svg?style=flat-square
|
||||
[npm-link]: https://www.npmjs.com/package/xxhash-wasm
|
||||
[release-notes-v1.0.0]: https://github.com/jungomi/xxhash-wasm/releases/tag/v1.0.0
|
||||
[textencoder-encodeinto-mdn]: https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder/encodeInto
|
||||
[travis]: https://travis-ci.org/jungomi/xxhash-wasm
|
||||
[travis-badge]: https://img.shields.io/travis/jungomi/xxhash-wasm/master.svg?style=flat-square
|
||||
[unpkg]: https://unpkg.com/
|
||||
[xxhash]: https://github.com/Cyan4973/xxHash
|
||||
[xxhashjs]: https://github.com/pierrec/js-xxhash
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
"use strict";const t=new Uint8Array([0,97,115,109,1,0,0,0,1,48,8,96,3,127,127,127,1,127,96,3,127,127,127,0,96,2,127,127,0,96,1,127,1,127,96,3,127,127,126,1,126,96,3,126,127,127,1,126,96,2,127,126,0,96,1,127,1,126,3,11,10,0,0,2,1,3,4,5,6,1,7,5,3,1,0,1,7,85,9,3,109,101,109,2,0,5,120,120,104,51,50,0,0,6,105,110,105,116,51,50,0,2,8,117,112,100,97,116,101,51,50,0,3,8,100,105,103,101,115,116,51,50,0,4,5,120,120,104,54,52,0,5,6,105,110,105,116,54,52,0,7,8,117,112,100,97,116,101,54,52,0,8,8,100,105,103,101,115,116,54,52,0,9,10,251,22,10,242,1,1,4,127,32,0,32,1,106,33,3,32,1,65,16,79,4,127,32,3,65,16,107,33,6,32,2,65,168,136,141,161,2,106,33,3,32,2,65,137,235,208,208,7,107,33,4,32,2,65,207,140,162,142,6,106,33,5,3,64,32,3,32,0,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,33,3,32,4,32,0,65,4,106,34,0,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,33,4,32,2,32,0,65,4,106,34,0,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,33,2,32,5,32,0,65,4,106,34,0,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,33,5,32,6,32,0,65,4,106,34,0,79,13,0,11,32,2,65,12,119,32,5,65,18,119,106,32,4,65,7,119,106,32,3,65,1,119,106,5,32,2,65,177,207,217,178,1,106,11,32,1,106,32,0,32,1,65,15,113,16,1,11,146,1,0,32,1,32,2,106,33,2,3,64,32,1,65,4,106,32,2,75,69,4,64,32,0,32,1,40,2,0,65,189,220,202,149,124,108,106,65,17,119,65,175,214,211,190,2,108,33,0,32,1,65,4,106,33,1,12,1,11,11,3,64,32,1,32,2,79,69,4,64,32,0,32,1,45,0,0,65,177,207,217,178,1,108,106,65,11,119,65,177,243,221,241,121,108,33,0,32,1,65,1,106,33,1,12,1,11,11,32,0,32,0,65,15,118,115,65,247,148,175,175,120,108,34,0,65,13,118,32,0,115,65,189,220,202,149,124,108,34,0,65,16,118,32,0,115,11,63,0,32,0,65,8,106,32,1,65,168,136,141,161,2,106,54,2,0,32,0,65,12,106,32,1,65,137,235,208,208,7,107,54,2,0,32,0,65,16,106,32,1,54,2,0,32,0,65,20,106,32,1,65,207,140,162,142,6,106,54,2,0,11,195,4,1,6,127,32,1,32,2,106,33,6,32,0,65,24,106,33,4,32,0,65,40,106,40,2,0,33,3,32,0,32,0,40,2,0,32,2,106,54,2,0,32,0,65,4,106,34,5,32,5,40,2,0,32,2,65,16,79,32,0,40,2,0,65,16,79,114,114,54,2,0,32,2,32,3,106,65,16,73,4,64,32,3,32,4,106,32,1,32,2,252,10,0,0,32,0,65,40,106,32,2,32,3,106,54,2,0,15,11,32,3,4,64,32,3,32,4,106,32,1,65,16,32,3,107,34,2,252,10,0,0,32,0,65,8,106,34,3,32,3,40,2,0,32,4,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,54,2,0,32,0,65,12,106,34,3,32,3,40,2,0,32,4,65,4,106,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,54,2,0,32,0,65,16,106,34,3,32,3,40,2,0,32,4,65,8,106,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,54,2,0,32,0,65,20,106,34,3,32,3,40,2,0,32,4,65,12,106,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,54,2,0,32,0,65,40,106,65,0,54,2,0,32,1,32,2,106,33,1,11,32,1,32,6,65,16,107,77,4,64,32,6,65,16,107,33,8,32,0,65,8,106,40,2,0,33,2,32,0,65,12,106,40,2,0,33,3,32,0,65,16,106,40,2,0,33,5,32,0,65,20,106,40,2,0,33,7,3,64,32,2,32,1,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,33,2,32,3,32,1,65,4,106,34,1,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,33,3,32,5,32,1,65,4,106,34,1,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,33,5,32,7,32,1,65,4,106,34,1,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,33,7,32,8,32,1,65,4,106,34,1,79,13,0,11,32,0,65,8,106,32,2,54,2,0,32,0,65,12,106,32,3,54,2,0,32,0,65,16,106,32,5,54,2,0,32,0,65,20,106,32,7,54,2,0,11,32,1,32,6,73,4,64,32,4,32,1,32,6,32,1,107,34,1,252,10,0,0,32,0,65,40,106,32,1,54,2,0,11,11,97,1,1,127,32,0,65,16,106,40,2,0,33,1,32,0,65,4,106,40,2,0,4,127,32,1,65,12,119,32,0,65,20,106,40,2,0,65,18,119,106,32,0,65,12,106,40,2,0,65,7,119,106,32,0,65,8,106,40,2,0,65,1,119,106,5,32,1,65,177,207,217,178,1,106,11,32,0,40,2,0,106,32,0,65,24,106,32,0,65,40,106,40,2,0,16,1,11,255,3,2,3,126,1,127,32,0,32,1,106,33,6,32,1,65,32,79,4,126,32,6,65,32,107,33,6,32,2,66,214,235,130,238,234,253,137,245,224,0,124,33,3,32,2,66,177,169,172,193,173,184,212,166,61,125,33,4,32,2,66,249,234,208,208,231,201,161,228,225,0,124,33,5,3,64,32,3,32,0,41,3,0,66,207,214,211,190,210,199,171,217,66,126,124,66,31,137,66,135,149,175,175,152,182,222,155,158,127,126,33,3,32,4,32,0,65,8,106,34,0,41,3,0,66,207,214,211,190,210,199,171,217,66,126,124,66,31,137,66,135,149,175,175,152,182,222,155,158,127,126,33,4,32,2,32,0,65,8,106,34,0,41,3,0,66,207,214,211,190,210,199,171,217,66,126,124,66,31,137,66,135,149,175,175,152,182,222,155,158,127,126,33,2,32,5,32,0,65,8,106,34,0,41,3,0,66,207,214,211,190,210,199,171,217,66,126,124,66,31,137,66,135,149,175,175,152,182,222,155,158,127,126,33,5,32,6,32,0,65,8,106,34,0,79,13,0,11,32,2,66,12,137,32,5,66,18,137,124,32,4,66,7,137,124,32,3,66,1,137,124,32,3,66,207,214,211,190,210,199,171,217,66,126,66,31,137,66,135,149,175,175,152,182,222,155,158,127,126,133,66,135,149,175,175,152,182,222,155,158,127,126,66,157,163,181,234,13Line truncated
|
||||
//# sourceMappingURL=xxhash-wasm.cjs.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"xxhash-wasm.cjs","sources":["../src/index.js","../src/xxhash.js"],"sourcesContent":["import { xxhash } from \"./xxhash\";\n\n// The .wasm is filled in by the build process, so the user doesn't need to load\n// xxhash.wasm by themselves because it's part of the bundle. Otherwise it\n// couldn't be distributed easily as the user would need to host xxhash.wasm\n// and then fetch it, to be able to use it.\n// eslint-disable-next-line no-undef\nconst wasmBytes = new Uint8Array(WASM_PRECOMPILED_BYTES);\n\nexport default async function () {\n return xxhash((await WebAssembly.instantiate(wasmBytes)).instance);\n}\n","const u32_BYTES = 4;\nconst u64_BYTES = 8;\n\n// The xxh32 hash state struct:\nconst XXH32_STATE_SIZE_BYTES =\n u32_BYTES + // total_len\n u32_BYTES + // large_len\n u32_BYTES * 4 + // Accumulator lanes\n u32_BYTES * 4 + // Internal buffer\n u32_BYTES + // memsize\n u32_BYTES; // reserved\n\n// The xxh64 hash state struct:\nconst XXH64_STATE_SIZE_BYTES =\n u64_BYTES + // total_len\n u64_BYTES * 4 + // Accumulator lanes\n u64_BYTES * 4 + // Internal buffer\n u32_BYTES + // memsize\n u32_BYTES + // reserved32\n u64_BYTES; // reserved64\n\nexport function xxhash(instance) {\n const {\n exports: {\n mem,\n xxh32,\n xxh64,\n init32,\n update32,\n digest32,\n init64,\n update64,\n digest64,\n },\n } = instance;\n\n let memory = new Uint8Array(mem.buffer);\n // Grow the wasm linear memory to accommodate length + offset bytes\n function growMemory(length, offset) {\n if (mem.buffer.byteLength < length + offset) {\n const extraPages = Math.ceil(\n // Wasm pages are spec'd to 64K\n (length + offset - mem.buffer.byteLength) / (64 * 1024),\n );\n mem.grow(extraPages);\n // After growing, the original memory's ArrayBuffer is detached, so we'll\n // need to replace our view over it with a new one over the new backing\n // ArrayBuffer.\n memory = new Uint8Array(mem.buffer);\n }\n }\n\n // The h32 and h64 streaming hash APIs are identical, so we can implement\n // them both by way of a templated call to this generalized function.\n function create(size, seed, init, update, digest, finalize) {\n // Ensure that we've actually got enough space in the wasm memory to store\n // the state blob for this hasher.\n growMemory(size);\n\n // We'll hold our hashing state in this closure.\n const state = new Uint8Array(size);\n memory.set(state);\n init(0, seed);\n\n // Each time we interact with wasm, it may have mutated our state so we'll\n // need to read it back into our closed copy.\n state.set(memory.subarray(0, size));\n\n return {\n update(input) {\n memory.set(state);\n let length;\n if (typeof input === \"string\") {\n growMemory(input.length * 3, size);\n length = encoder.encodeInto(input, memory.subarray(size)).written;\n } else {\n // The only other valid input type is a Uint8Array\n growMemory(input.byteLength, size);\n memory.set(input, size);\n length = input.byteLength;\n }\n update(0, size, length);\n state.set(memory.subarray(0, size));\n return this;\n },\n digest() {\n memory.set(state);\n return finalize(digest(0));\n },\n };\n }\n\n // Logical shift right makes it an u32, otherwise it's interpreted as an i32.\n function forceUnsigned32(i) {\n return i >>> 0;\n }\n\n // BigInts are arbitrary precision and signed, so to get the \"correct\" u64\n // value from the return, we'll need to force that interpretation.\n const u64Max = 2n ** 64n - 1n;\n function forceUnsigned64(i) {\n return i & u64Max;\n }\n\n const encoder = new TextEncoder();\n const defaultSeed = 0;\n const defaultBigSeed = 0n;\n\n function h32(str, seed = defaultSeed) {\n // https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder/encodeInto#buffer_sizing\n // By sizing the buffer to 3 * string-length we guarantee that the buffer\n // will be appropriately sized for the utf-8 encoding of the string.\n growMemory(str.length * 3, 0);\n return forceUnsigned32(\n xxh32(0, encoder.encodeInto(str, memory).written, seed),\n );\n }\n\n function h64(str, seed = defaultBigSeed) {\n growMemory(str.length * 3, 0);\n return forceUnsigned64(\n xxh64(0, encoder.encodeInto(str, memory).written, seed),\n );\n }\n\n return {\n h32,\n h32ToString(str, seed = defaultSeed) {\n return h32(str, seed).toString(16).padStart(8, \"0\");\n },\n h32Raw(inputBuffer, seed = defaultSeed) {\n growMemory(inputBuffer.byteLength, 0);\n memory.set(inputBuffer);\n return forceUnsigned32(xxh32(0, inputBuffer.byteLength, seed));\n },\n create32(seed = defaultSeed) {\n return create(\n XXH32_STATE_SIZE_BYTES,\n seed,\n init32,\n uLine truncated
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
const t=new Uint8Array([0,97,115,109,1,0,0,0,1,48,8,96,3,127,127,127,1,127,96,3,127,127,127,0,96,2,127,127,0,96,1,127,1,127,96,3,127,127,126,1,126,96,3,126,127,127,1,126,96,2,127,126,0,96,1,127,1,126,3,11,10,0,0,2,1,3,4,5,6,1,7,5,3,1,0,1,7,85,9,3,109,101,109,2,0,5,120,120,104,51,50,0,0,6,105,110,105,116,51,50,0,2,8,117,112,100,97,116,101,51,50,0,3,8,100,105,103,101,115,116,51,50,0,4,5,120,120,104,54,52,0,5,6,105,110,105,116,54,52,0,7,8,117,112,100,97,116,101,54,52,0,8,8,100,105,103,101,115,116,54,52,0,9,10,251,22,10,242,1,1,4,127,32,0,32,1,106,33,3,32,1,65,16,79,4,127,32,3,65,16,107,33,6,32,2,65,168,136,141,161,2,106,33,3,32,2,65,137,235,208,208,7,107,33,4,32,2,65,207,140,162,142,6,106,33,5,3,64,32,3,32,0,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,33,3,32,4,32,0,65,4,106,34,0,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,33,4,32,2,32,0,65,4,106,34,0,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,33,2,32,5,32,0,65,4,106,34,0,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,33,5,32,6,32,0,65,4,106,34,0,79,13,0,11,32,2,65,12,119,32,5,65,18,119,106,32,4,65,7,119,106,32,3,65,1,119,106,5,32,2,65,177,207,217,178,1,106,11,32,1,106,32,0,32,1,65,15,113,16,1,11,146,1,0,32,1,32,2,106,33,2,3,64,32,1,65,4,106,32,2,75,69,4,64,32,0,32,1,40,2,0,65,189,220,202,149,124,108,106,65,17,119,65,175,214,211,190,2,108,33,0,32,1,65,4,106,33,1,12,1,11,11,3,64,32,1,32,2,79,69,4,64,32,0,32,1,45,0,0,65,177,207,217,178,1,108,106,65,11,119,65,177,243,221,241,121,108,33,0,32,1,65,1,106,33,1,12,1,11,11,32,0,32,0,65,15,118,115,65,247,148,175,175,120,108,34,0,65,13,118,32,0,115,65,189,220,202,149,124,108,34,0,65,16,118,32,0,115,11,63,0,32,0,65,8,106,32,1,65,168,136,141,161,2,106,54,2,0,32,0,65,12,106,32,1,65,137,235,208,208,7,107,54,2,0,32,0,65,16,106,32,1,54,2,0,32,0,65,20,106,32,1,65,207,140,162,142,6,106,54,2,0,11,195,4,1,6,127,32,1,32,2,106,33,6,32,0,65,24,106,33,4,32,0,65,40,106,40,2,0,33,3,32,0,32,0,40,2,0,32,2,106,54,2,0,32,0,65,4,106,34,5,32,5,40,2,0,32,2,65,16,79,32,0,40,2,0,65,16,79,114,114,54,2,0,32,2,32,3,106,65,16,73,4,64,32,3,32,4,106,32,1,32,2,252,10,0,0,32,0,65,40,106,32,2,32,3,106,54,2,0,15,11,32,3,4,64,32,3,32,4,106,32,1,65,16,32,3,107,34,2,252,10,0,0,32,0,65,8,106,34,3,32,3,40,2,0,32,4,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,54,2,0,32,0,65,12,106,34,3,32,3,40,2,0,32,4,65,4,106,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,54,2,0,32,0,65,16,106,34,3,32,3,40,2,0,32,4,65,8,106,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,54,2,0,32,0,65,20,106,34,3,32,3,40,2,0,32,4,65,12,106,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,54,2,0,32,0,65,40,106,65,0,54,2,0,32,1,32,2,106,33,1,11,32,1,32,6,65,16,107,77,4,64,32,6,65,16,107,33,8,32,0,65,8,106,40,2,0,33,2,32,0,65,12,106,40,2,0,33,3,32,0,65,16,106,40,2,0,33,5,32,0,65,20,106,40,2,0,33,7,3,64,32,2,32,1,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,33,2,32,3,32,1,65,4,106,34,1,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,33,3,32,5,32,1,65,4,106,34,1,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,33,5,32,7,32,1,65,4,106,34,1,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,33,7,32,8,32,1,65,4,106,34,1,79,13,0,11,32,0,65,8,106,32,2,54,2,0,32,0,65,12,106,32,3,54,2,0,32,0,65,16,106,32,5,54,2,0,32,0,65,20,106,32,7,54,2,0,11,32,1,32,6,73,4,64,32,4,32,1,32,6,32,1,107,34,1,252,10,0,0,32,0,65,40,106,32,1,54,2,0,11,11,97,1,1,127,32,0,65,16,106,40,2,0,33,1,32,0,65,4,106,40,2,0,4,127,32,1,65,12,119,32,0,65,20,106,40,2,0,65,18,119,106,32,0,65,12,106,40,2,0,65,7,119,106,32,0,65,8,106,40,2,0,65,1,119,106,5,32,1,65,177,207,217,178,1,106,11,32,0,40,2,0,106,32,0,65,24,106,32,0,65,40,106,40,2,0,16,1,11,255,3,2,3,126,1,127,32,0,32,1,106,33,6,32,1,65,32,79,4,126,32,6,65,32,107,33,6,32,2,66,214,235,130,238,234,253,137,245,224,0,124,33,3,32,2,66,177,169,172,193,173,184,212,166,61,125,33,4,32,2,66,249,234,208,208,231,201,161,228,225,0,124,33,5,3,64,32,3,32,0,41,3,0,66,207,214,211,190,210,199,171,217,66,126,124,66,31,137,66,135,149,175,175,152,182,222,155,158,127,126,33,3,32,4,32,0,65,8,106,34,0,41,3,0,66,207,214,211,190,210,199,171,217,66,126,124,66,31,137,66,135,149,175,175,152,182,222,155,158,127,126,33,4,32,2,32,0,65,8,106,34,0,41,3,0,66,207,214,211,190,210,199,171,217,66,126,124,66,31,137,66,135,149,175,175,152,182,222,155,158,127,126,33,2,32,5,32,0,65,8,106,34,0,41,3,0,66,207,214,211,190,210,199,171,217,66,126,124,66,31,137,66,135,149,175,175,152,182,222,155,158,127,126,33,5,32,6,32,0,65,8,106,34,0,79,13,0,11,32,2,66,12,137,32,5,66,18,137,124,32,4,66,7,137,124,32,3,66,1,137,124,32,3,66,207,214,211,190,210,199,171,217,66,126,66,31,137,66,135,149,175,175,152,182,222,155,158,127,126,133,66,135,149,175,175,152,182,222,155,158,127,126,66,157,163,181,234,131,177,141,138Line truncated
|
||||
//# sourceMappingURL=xxhash-wasm.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"xxhash-wasm.js","sources":["../src/index.js","../src/xxhash.js"],"sourcesContent":["import { xxhash } from \"./xxhash\";\n\n// The .wasm is filled in by the build process, so the user doesn't need to load\n// xxhash.wasm by themselves because it's part of the bundle. Otherwise it\n// couldn't be distributed easily as the user would need to host xxhash.wasm\n// and then fetch it, to be able to use it.\n// eslint-disable-next-line no-undef\nconst wasmBytes = new Uint8Array(WASM_PRECOMPILED_BYTES);\n\nexport default async function () {\n return xxhash((await WebAssembly.instantiate(wasmBytes)).instance);\n}\n","const u32_BYTES = 4;\nconst u64_BYTES = 8;\n\n// The xxh32 hash state struct:\nconst XXH32_STATE_SIZE_BYTES =\n u32_BYTES + // total_len\n u32_BYTES + // large_len\n u32_BYTES * 4 + // Accumulator lanes\n u32_BYTES * 4 + // Internal buffer\n u32_BYTES + // memsize\n u32_BYTES; // reserved\n\n// The xxh64 hash state struct:\nconst XXH64_STATE_SIZE_BYTES =\n u64_BYTES + // total_len\n u64_BYTES * 4 + // Accumulator lanes\n u64_BYTES * 4 + // Internal buffer\n u32_BYTES + // memsize\n u32_BYTES + // reserved32\n u64_BYTES; // reserved64\n\nexport function xxhash(instance) {\n const {\n exports: {\n mem,\n xxh32,\n xxh64,\n init32,\n update32,\n digest32,\n init64,\n update64,\n digest64,\n },\n } = instance;\n\n let memory = new Uint8Array(mem.buffer);\n // Grow the wasm linear memory to accommodate length + offset bytes\n function growMemory(length, offset) {\n if (mem.buffer.byteLength < length + offset) {\n const extraPages = Math.ceil(\n // Wasm pages are spec'd to 64K\n (length + offset - mem.buffer.byteLength) / (64 * 1024),\n );\n mem.grow(extraPages);\n // After growing, the original memory's ArrayBuffer is detached, so we'll\n // need to replace our view over it with a new one over the new backing\n // ArrayBuffer.\n memory = new Uint8Array(mem.buffer);\n }\n }\n\n // The h32 and h64 streaming hash APIs are identical, so we can implement\n // them both by way of a templated call to this generalized function.\n function create(size, seed, init, update, digest, finalize) {\n // Ensure that we've actually got enough space in the wasm memory to store\n // the state blob for this hasher.\n growMemory(size);\n\n // We'll hold our hashing state in this closure.\n const state = new Uint8Array(size);\n memory.set(state);\n init(0, seed);\n\n // Each time we interact with wasm, it may have mutated our state so we'll\n // need to read it back into our closed copy.\n state.set(memory.subarray(0, size));\n\n return {\n update(input) {\n memory.set(state);\n let length;\n if (typeof input === \"string\") {\n growMemory(input.length * 3, size);\n length = encoder.encodeInto(input, memory.subarray(size)).written;\n } else {\n // The only other valid input type is a Uint8Array\n growMemory(input.byteLength, size);\n memory.set(input, size);\n length = input.byteLength;\n }\n update(0, size, length);\n state.set(memory.subarray(0, size));\n return this;\n },\n digest() {\n memory.set(state);\n return finalize(digest(0));\n },\n };\n }\n\n // Logical shift right makes it an u32, otherwise it's interpreted as an i32.\n function forceUnsigned32(i) {\n return i >>> 0;\n }\n\n // BigInts are arbitrary precision and signed, so to get the \"correct\" u64\n // value from the return, we'll need to force that interpretation.\n const u64Max = 2n ** 64n - 1n;\n function forceUnsigned64(i) {\n return i & u64Max;\n }\n\n const encoder = new TextEncoder();\n const defaultSeed = 0;\n const defaultBigSeed = 0n;\n\n function h32(str, seed = defaultSeed) {\n // https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder/encodeInto#buffer_sizing\n // By sizing the buffer to 3 * string-length we guarantee that the buffer\n // will be appropriately sized for the utf-8 encoding of the string.\n growMemory(str.length * 3, 0);\n return forceUnsigned32(\n xxh32(0, encoder.encodeInto(str, memory).written, seed),\n );\n }\n\n function h64(str, seed = defaultBigSeed) {\n growMemory(str.length * 3, 0);\n return forceUnsigned64(\n xxh64(0, encoder.encodeInto(str, memory).written, seed),\n );\n }\n\n return {\n h32,\n h32ToString(str, seed = defaultSeed) {\n return h32(str, seed).toString(16).padStart(8, \"0\");\n },\n h32Raw(inputBuffer, seed = defaultSeed) {\n growMemory(inputBuffer.byteLength, 0);\n memory.set(inputBuffer);\n return forceUnsigned32(xxh32(0, inputBuffer.byteLength, seed));\n },\n create32(seed = defaultSeed) {\n return create(\n XXH32_STATE_SIZE_BYTES,\n seed,\n init32,\n upLine truncated
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
{
|
||||
"name": "xxhash-wasm",
|
||||
"version": "1.1.0",
|
||||
"description": "A WebAssembly implementation of xxHash",
|
||||
"type": "module",
|
||||
"main": "./cjs/xxhash-wasm.cjs",
|
||||
"module": "./esm/xxhash-wasm.js",
|
||||
"exports": {
|
||||
"types": "./types.d.ts",
|
||||
"workerd": "./workerd/xxhash-wasm.js",
|
||||
"import": "./esm/xxhash-wasm.js",
|
||||
"require": "./cjs/xxhash-wasm.cjs"
|
||||
},
|
||||
"types": "./types.d.ts",
|
||||
"author": "Michael Jungo <michaeljungo92@gmail.com>",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/jungomi/xxhash-wasm.git"
|
||||
},
|
||||
"files": [
|
||||
"cjs",
|
||||
"esm",
|
||||
"umd",
|
||||
"workerd",
|
||||
"types.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"xxhash",
|
||||
"hash",
|
||||
"wasm",
|
||||
"webassembly"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "yarn run build-wasm && yarn run build-js",
|
||||
"build-js": "rollup -c",
|
||||
"build-wasm": "wasm-opt --enable-bulk-memory -O4 src/xxhash.wat -o src/xxhash.wasm",
|
||||
"clean": "rimraf coverage cjs esm umd",
|
||||
"fix": "eslint . --fix",
|
||||
"lint": "eslint .",
|
||||
"size": "bundlewatch",
|
||||
"test": "jest",
|
||||
"test-update": "jest --updateSnapshot",
|
||||
"test-coverage": "jest --coverage",
|
||||
"prebuild": "yarn run clean",
|
||||
"prepublish": "yarn run build"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.26.0",
|
||||
"@babel/eslint-parser": "^7.25.9",
|
||||
"@eslint/eslintrc": "^3.2.0",
|
||||
"@eslint/js": "^9.15.0",
|
||||
"@swc/core": "^1.9.2",
|
||||
"@swc/jest": "^0.2.37",
|
||||
"bundlewatch": "^0.4.0",
|
||||
"eslint": "^9.15.0",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-plugin-prettier": "^5.2.1",
|
||||
"globals": "^15.12.0",
|
||||
"jest": "^29.7.0",
|
||||
"jest-t-assert": "^0.3.0",
|
||||
"node-gyp": "^10.2.0",
|
||||
"prettier": "^3.3.3",
|
||||
"rimraf": "^6.0.1",
|
||||
"rollup": "^4.27.3",
|
||||
"rollup-plugin-copy": "^3.5.0",
|
||||
"rollup-plugin-node-resolve": "^5.2.0",
|
||||
"rollup-plugin-replace": "^2.2.0",
|
||||
"rollup-plugin-swc3": "^0.12.1"
|
||||
},
|
||||
"bundlewatch": {
|
||||
"files": [
|
||||
{
|
||||
"path": "./cjs/xxhash-wasm.cjs",
|
||||
"maxSize": "2.2kb"
|
||||
},
|
||||
{
|
||||
"path": "./esm/xxhash-wasm.js",
|
||||
"maxSize": "2.2kb"
|
||||
},
|
||||
{
|
||||
"path": "./umd/xxhash-wasm.js",
|
||||
"maxSize": "2.3kb"
|
||||
}
|
||||
]
|
||||
},
|
||||
"packageManager": "yarn@4.5.1"
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
export type XXHash<T> = {
|
||||
update(input: string | Uint8Array): XXHash<T>;
|
||||
digest(): T;
|
||||
}
|
||||
|
||||
export type XXHashAPI = {
|
||||
h32(input: string, seed?: number): number;
|
||||
h32ToString(input: string, seed?: number): string;
|
||||
h32Raw(inputBuffer: Uint8Array, seed?: number): number;
|
||||
create32(seed?: number): XXHash<number>;
|
||||
h64(input: string, seed?: bigint): bigint;
|
||||
h64ToString(input: string, seed?: bigint): string;
|
||||
h64Raw(inputBuffer: Uint8Array, seed?: bigint): bigint;
|
||||
create64(seed?: bigint): XXHash<bigint>;
|
||||
};
|
||||
|
||||
declare module "xxhash-wasm" {
|
||||
export default function xxhash(): Promise<XXHashAPI>;
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
var t,e;t=this,e=function(){"use strict";const t=new Uint8Array([0,97,115,109,1,0,0,0,1,48,8,96,3,127,127,127,1,127,96,3,127,127,127,0,96,2,127,127,0,96,1,127,1,127,96,3,127,127,126,1,126,96,3,126,127,127,1,126,96,2,127,126,0,96,1,127,1,126,3,11,10,0,0,2,1,3,4,5,6,1,7,5,3,1,0,1,7,85,9,3,109,101,109,2,0,5,120,120,104,51,50,0,0,6,105,110,105,116,51,50,0,2,8,117,112,100,97,116,101,51,50,0,3,8,100,105,103,101,115,116,51,50,0,4,5,120,120,104,54,52,0,5,6,105,110,105,116,54,52,0,7,8,117,112,100,97,116,101,54,52,0,8,8,100,105,103,101,115,116,54,52,0,9,10,251,22,10,242,1,1,4,127,32,0,32,1,106,33,3,32,1,65,16,79,4,127,32,3,65,16,107,33,6,32,2,65,168,136,141,161,2,106,33,3,32,2,65,137,235,208,208,7,107,33,4,32,2,65,207,140,162,142,6,106,33,5,3,64,32,3,32,0,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,33,3,32,4,32,0,65,4,106,34,0,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,33,4,32,2,32,0,65,4,106,34,0,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,33,2,32,5,32,0,65,4,106,34,0,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,33,5,32,6,32,0,65,4,106,34,0,79,13,0,11,32,2,65,12,119,32,5,65,18,119,106,32,4,65,7,119,106,32,3,65,1,119,106,5,32,2,65,177,207,217,178,1,106,11,32,1,106,32,0,32,1,65,15,113,16,1,11,146,1,0,32,1,32,2,106,33,2,3,64,32,1,65,4,106,32,2,75,69,4,64,32,0,32,1,40,2,0,65,189,220,202,149,124,108,106,65,17,119,65,175,214,211,190,2,108,33,0,32,1,65,4,106,33,1,12,1,11,11,3,64,32,1,32,2,79,69,4,64,32,0,32,1,45,0,0,65,177,207,217,178,1,108,106,65,11,119,65,177,243,221,241,121,108,33,0,32,1,65,1,106,33,1,12,1,11,11,32,0,32,0,65,15,118,115,65,247,148,175,175,120,108,34,0,65,13,118,32,0,115,65,189,220,202,149,124,108,34,0,65,16,118,32,0,115,11,63,0,32,0,65,8,106,32,1,65,168,136,141,161,2,106,54,2,0,32,0,65,12,106,32,1,65,137,235,208,208,7,107,54,2,0,32,0,65,16,106,32,1,54,2,0,32,0,65,20,106,32,1,65,207,140,162,142,6,106,54,2,0,11,195,4,1,6,127,32,1,32,2,106,33,6,32,0,65,24,106,33,4,32,0,65,40,106,40,2,0,33,3,32,0,32,0,40,2,0,32,2,106,54,2,0,32,0,65,4,106,34,5,32,5,40,2,0,32,2,65,16,79,32,0,40,2,0,65,16,79,114,114,54,2,0,32,2,32,3,106,65,16,73,4,64,32,3,32,4,106,32,1,32,2,252,10,0,0,32,0,65,40,106,32,2,32,3,106,54,2,0,15,11,32,3,4,64,32,3,32,4,106,32,1,65,16,32,3,107,34,2,252,10,0,0,32,0,65,8,106,34,3,32,3,40,2,0,32,4,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,54,2,0,32,0,65,12,106,34,3,32,3,40,2,0,32,4,65,4,106,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,54,2,0,32,0,65,16,106,34,3,32,3,40,2,0,32,4,65,8,106,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,54,2,0,32,0,65,20,106,34,3,32,3,40,2,0,32,4,65,12,106,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,54,2,0,32,0,65,40,106,65,0,54,2,0,32,1,32,2,106,33,1,11,32,1,32,6,65,16,107,77,4,64,32,6,65,16,107,33,8,32,0,65,8,106,40,2,0,33,2,32,0,65,12,106,40,2,0,33,3,32,0,65,16,106,40,2,0,33,5,32,0,65,20,106,40,2,0,33,7,3,64,32,2,32,1,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,33,2,32,3,32,1,65,4,106,34,1,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,33,3,32,5,32,1,65,4,106,34,1,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,33,5,32,7,32,1,65,4,106,34,1,40,2,0,65,247,148,175,175,120,108,106,65,13,119,65,177,243,221,241,121,108,33,7,32,8,32,1,65,4,106,34,1,79,13,0,11,32,0,65,8,106,32,2,54,2,0,32,0,65,12,106,32,3,54,2,0,32,0,65,16,106,32,5,54,2,0,32,0,65,20,106,32,7,54,2,0,11,32,1,32,6,73,4,64,32,4,32,1,32,6,32,1,107,34,1,252,10,0,0,32,0,65,40,106,32,1,54,2,0,11,11,97,1,1,127,32,0,65,16,106,40,2,0,33,1,32,0,65,4,106,40,2,0,4,127,32,1,65,12,119,32,0,65,20,106,40,2,0,65,18,119,106,32,0,65,12,106,40,2,0,65,7,119,106,32,0,65,8,106,40,2,0,65,1,119,106,5,32,1,65,177,207,217,178,1,106,11,32,0,40,2,0,106,32,0,65,24,106,32,0,65,40,106,40,2,0,16,1,11,255,3,2,3,126,1,127,32,0,32,1,106,33,6,32,1,65,32,79,4,126,32,6,65,32,107,33,6,32,2,66,214,235,130,238,234,253,137,245,224,0,124,33,3,32,2,66,177,169,172,193,173,184,212,166,61,125,33,4,32,2,66,249,234,208,208,231,201,161,228,225,0,124,33,5,3,64,32,3,32,0,41,3,0,66,207,214,211,190,210,199,171,217,66,126,124,66,31,137,66,135,149,175,175,152,182,222,155,158,127,126,33,3,32,4,32,0,65,8,106,34,0,41,3,0,66,207,214,211,190,210,199,171,217,66,126,124,66,31,137,66,135,149,175,175,152,182,222,155,158,127,126,33,4,32,2,32,0,65,8,106,34,0,41,3,0,66,207,214,211,190,210,199,171,217,66,126,124,66,31,137,66,135,149,175,175,152,182,222,155,158,127,126,33,2,32,5,32,0,65,8,106,34,0,41,3,0,66,207,214,211,190,210,199,171,217,66,126,124,66,31,137,66,135,149,175,175,152,182,222,155,158,127,126,33,5,32,6,32,0,65,8,106,34,0,79,13,0,11,32,2,66,12,137,32,5,66,18,137,124,32,4,66,7,137,124,32,3,66,1,137,124,32,3,66,207,214,211,190,210,199,171,217,66,126,66,31,137,66,135,149,175,175,152,182,222,155,158,127,126,133,66,135,149,175,175,152,182,222,155,158,1Line truncated
|
||||
//# sourceMappingURL=xxhash-wasm.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"xxhash-wasm.js","sources":["../src/index.js","../src/xxhash.js"],"sourcesContent":["import { xxhash } from \"./xxhash\";\n\n// The .wasm is filled in by the build process, so the user doesn't need to load\n// xxhash.wasm by themselves because it's part of the bundle. Otherwise it\n// couldn't be distributed easily as the user would need to host xxhash.wasm\n// and then fetch it, to be able to use it.\n// eslint-disable-next-line no-undef\nconst wasmBytes = new Uint8Array(WASM_PRECOMPILED_BYTES);\n\nexport default async function () {\n return xxhash((await WebAssembly.instantiate(wasmBytes)).instance);\n}\n","const u32_BYTES = 4;\nconst u64_BYTES = 8;\n\n// The xxh32 hash state struct:\nconst XXH32_STATE_SIZE_BYTES =\n u32_BYTES + // total_len\n u32_BYTES + // large_len\n u32_BYTES * 4 + // Accumulator lanes\n u32_BYTES * 4 + // Internal buffer\n u32_BYTES + // memsize\n u32_BYTES; // reserved\n\n// The xxh64 hash state struct:\nconst XXH64_STATE_SIZE_BYTES =\n u64_BYTES + // total_len\n u64_BYTES * 4 + // Accumulator lanes\n u64_BYTES * 4 + // Internal buffer\n u32_BYTES + // memsize\n u32_BYTES + // reserved32\n u64_BYTES; // reserved64\n\nexport function xxhash(instance) {\n const {\n exports: {\n mem,\n xxh32,\n xxh64,\n init32,\n update32,\n digest32,\n init64,\n update64,\n digest64,\n },\n } = instance;\n\n let memory = new Uint8Array(mem.buffer);\n // Grow the wasm linear memory to accommodate length + offset bytes\n function growMemory(length, offset) {\n if (mem.buffer.byteLength < length + offset) {\n const extraPages = Math.ceil(\n // Wasm pages are spec'd to 64K\n (length + offset - mem.buffer.byteLength) / (64 * 1024),\n );\n mem.grow(extraPages);\n // After growing, the original memory's ArrayBuffer is detached, so we'll\n // need to replace our view over it with a new one over the new backing\n // ArrayBuffer.\n memory = new Uint8Array(mem.buffer);\n }\n }\n\n // The h32 and h64 streaming hash APIs are identical, so we can implement\n // them both by way of a templated call to this generalized function.\n function create(size, seed, init, update, digest, finalize) {\n // Ensure that we've actually got enough space in the wasm memory to store\n // the state blob for this hasher.\n growMemory(size);\n\n // We'll hold our hashing state in this closure.\n const state = new Uint8Array(size);\n memory.set(state);\n init(0, seed);\n\n // Each time we interact with wasm, it may have mutated our state so we'll\n // need to read it back into our closed copy.\n state.set(memory.subarray(0, size));\n\n return {\n update(input) {\n memory.set(state);\n let length;\n if (typeof input === \"string\") {\n growMemory(input.length * 3, size);\n length = encoder.encodeInto(input, memory.subarray(size)).written;\n } else {\n // The only other valid input type is a Uint8Array\n growMemory(input.byteLength, size);\n memory.set(input, size);\n length = input.byteLength;\n }\n update(0, size, length);\n state.set(memory.subarray(0, size));\n return this;\n },\n digest() {\n memory.set(state);\n return finalize(digest(0));\n },\n };\n }\n\n // Logical shift right makes it an u32, otherwise it's interpreted as an i32.\n function forceUnsigned32(i) {\n return i >>> 0;\n }\n\n // BigInts are arbitrary precision and signed, so to get the \"correct\" u64\n // value from the return, we'll need to force that interpretation.\n const u64Max = 2n ** 64n - 1n;\n function forceUnsigned64(i) {\n return i & u64Max;\n }\n\n const encoder = new TextEncoder();\n const defaultSeed = 0;\n const defaultBigSeed = 0n;\n\n function h32(str, seed = defaultSeed) {\n // https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder/encodeInto#buffer_sizing\n // By sizing the buffer to 3 * string-length we guarantee that the buffer\n // will be appropriately sized for the utf-8 encoding of the string.\n growMemory(str.length * 3, 0);\n return forceUnsigned32(\n xxh32(0, encoder.encodeInto(str, memory).written, seed),\n );\n }\n\n function h64(str, seed = defaultBigSeed) {\n growMemory(str.length * 3, 0);\n return forceUnsigned64(\n xxh64(0, encoder.encodeInto(str, memory).written, seed),\n );\n }\n\n return {\n h32,\n h32ToString(str, seed = defaultSeed) {\n return h32(str, seed).toString(16).padStart(8, \"0\");\n },\n h32Raw(inputBuffer, seed = defaultSeed) {\n growMemory(inputBuffer.byteLength, 0);\n memory.set(inputBuffer);\n return forceUnsigned32(xxh32(0, inputBuffer.byteLength, seed));\n },\n create32(seed = defaultSeed) {\n return create(\n XXH32_STATE_SIZE_BYTES,\n seed,\n init32,\n upLine truncated
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
import t from"./xxhash.wasm";async function e(){return function(t){const{exports:{mem:e,xxh32:n,xxh64:r,init32:i,update32:o,digest32:a,init64:s,update64:u,digest64:h}}=t;let c=new Uint8Array(e.buffer);function f(t,n){if(e.buffer.byteLength<t+n){const r=Math.ceil((t+n-e.buffer.byteLength)/65536);e.grow(r),c=new Uint8Array(e.buffer)}}function g(t,e,n,r,i,o){f(t);const a=new Uint8Array(t);return c.set(a),n(0,e),a.set(c.subarray(0,t)),{update(e){let n;return c.set(a),"string"==typeof e?(f(3*e.length,t),n=w.encodeInto(e,c.subarray(t)).written):(f(e.byteLength,t),c.set(e,t),n=e.byteLength),r(0,t,n),a.set(c.subarray(0,t)),this},digest:()=>(c.set(a),o(i(0)))}}function b(t){return t>>>0}const y=2n**64n-1n;function d(t){return t&y}const w=new TextEncoder,x=0,p=0n;function l(t,e=x){return f(3*t.length,0),b(n(0,w.encodeInto(t,c).written,e))}function L(t,e=p){return f(3*t.length,0),d(r(0,w.encodeInto(t,c).written,e))}return{h32:l,h32ToString:(t,e=x)=>l(t,e).toString(16).padStart(8,"0"),h32Raw:(t,e=x)=>(f(t.byteLength,0),c.set(t),b(n(0,t.byteLength,e))),create32:(t=x)=>g(48,t,i,o,a,b),h64:L,h64ToString:(t,e=p)=>L(t,e).toString(16).padStart(16,"0"),h64Raw:(t,e=p)=>(f(t.byteLength,0),c.set(t),d(r(0,t.byteLength,e))),create64:(t=p)=>g(88,t,s,u,h,d)}}(await WebAssembly.instantiate(t))}export{e as default};
|
||||
//# sourceMappingURL=xxhash-wasm.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"xxhash-wasm.js","sources":["../src/index.workerd.js","../src/xxhash.js"],"sourcesContent":["import { xxhash } from \"./xxhash\";\n\n// In CloudFlare workerd we must use import to prevent code injection.\nimport module from \"./xxhash.wasm\";\n\nexport default async function () {\n return xxhash(await WebAssembly.instantiate(module));\n}\n","const u32_BYTES = 4;\nconst u64_BYTES = 8;\n\n// The xxh32 hash state struct:\nconst XXH32_STATE_SIZE_BYTES =\n u32_BYTES + // total_len\n u32_BYTES + // large_len\n u32_BYTES * 4 + // Accumulator lanes\n u32_BYTES * 4 + // Internal buffer\n u32_BYTES + // memsize\n u32_BYTES; // reserved\n\n// The xxh64 hash state struct:\nconst XXH64_STATE_SIZE_BYTES =\n u64_BYTES + // total_len\n u64_BYTES * 4 + // Accumulator lanes\n u64_BYTES * 4 + // Internal buffer\n u32_BYTES + // memsize\n u32_BYTES + // reserved32\n u64_BYTES; // reserved64\n\nexport function xxhash(instance) {\n const {\n exports: {\n mem,\n xxh32,\n xxh64,\n init32,\n update32,\n digest32,\n init64,\n update64,\n digest64,\n },\n } = instance;\n\n let memory = new Uint8Array(mem.buffer);\n // Grow the wasm linear memory to accommodate length + offset bytes\n function growMemory(length, offset) {\n if (mem.buffer.byteLength < length + offset) {\n const extraPages = Math.ceil(\n // Wasm pages are spec'd to 64K\n (length + offset - mem.buffer.byteLength) / (64 * 1024),\n );\n mem.grow(extraPages);\n // After growing, the original memory's ArrayBuffer is detached, so we'll\n // need to replace our view over it with a new one over the new backing\n // ArrayBuffer.\n memory = new Uint8Array(mem.buffer);\n }\n }\n\n // The h32 and h64 streaming hash APIs are identical, so we can implement\n // them both by way of a templated call to this generalized function.\n function create(size, seed, init, update, digest, finalize) {\n // Ensure that we've actually got enough space in the wasm memory to store\n // the state blob for this hasher.\n growMemory(size);\n\n // We'll hold our hashing state in this closure.\n const state = new Uint8Array(size);\n memory.set(state);\n init(0, seed);\n\n // Each time we interact with wasm, it may have mutated our state so we'll\n // need to read it back into our closed copy.\n state.set(memory.subarray(0, size));\n\n return {\n update(input) {\n memory.set(state);\n let length;\n if (typeof input === \"string\") {\n growMemory(input.length * 3, size);\n length = encoder.encodeInto(input, memory.subarray(size)).written;\n } else {\n // The only other valid input type is a Uint8Array\n growMemory(input.byteLength, size);\n memory.set(input, size);\n length = input.byteLength;\n }\n update(0, size, length);\n state.set(memory.subarray(0, size));\n return this;\n },\n digest() {\n memory.set(state);\n return finalize(digest(0));\n },\n };\n }\n\n // Logical shift right makes it an u32, otherwise it's interpreted as an i32.\n function forceUnsigned32(i) {\n return i >>> 0;\n }\n\n // BigInts are arbitrary precision and signed, so to get the \"correct\" u64\n // value from the return, we'll need to force that interpretation.\n const u64Max = 2n ** 64n - 1n;\n function forceUnsigned64(i) {\n return i & u64Max;\n }\n\n const encoder = new TextEncoder();\n const defaultSeed = 0;\n const defaultBigSeed = 0n;\n\n function h32(str, seed = defaultSeed) {\n // https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder/encodeInto#buffer_sizing\n // By sizing the buffer to 3 * string-length we guarantee that the buffer\n // will be appropriately sized for the utf-8 encoding of the string.\n growMemory(str.length * 3, 0);\n return forceUnsigned32(\n xxh32(0, encoder.encodeInto(str, memory).written, seed),\n );\n }\n\n function h64(str, seed = defaultBigSeed) {\n growMemory(str.length * 3, 0);\n return forceUnsigned64(\n xxh64(0, encoder.encodeInto(str, memory).written, seed),\n );\n }\n\n return {\n h32,\n h32ToString(str, seed = defaultSeed) {\n return h32(str, seed).toString(16).padStart(8, \"0\");\n },\n h32Raw(inputBuffer, seed = defaultSeed) {\n growMemory(inputBuffer.byteLength, 0);\n memory.set(inputBuffer);\n return forceUnsigned32(xxh32(0, inputBuffer.byteLength, seed));\n },\n create32(seed = defaultSeed) {\n return create(\n XXH32_STATE_SIZE_BYTES,\n seed,\n init32,\n update32,\n digest32,\n forceUnsigned32,\n );\n },\n h64,\n h64ToString(str, seed = defaultBigSeed) {\n return h64(str, seed).toString(16).padStart(16, \"0\");\n },\n h64Raw(inputBuffer, seed = defaultBigSeed) {\n growMemory(inputBLine truncated
|
||||
BIN
Binary file not shown.
Reference in new issue
Block a user