-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: do encoding transform in node for speed and size
- Loading branch information
1 parent
adc1fdd
commit 01a756f
Showing
9 changed files
with
98 additions
and
135 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#------------------------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. | ||
#------------------------------------------------------------------------------------------------------------- | ||
|
||
# To fully customize the contents of this image, use the following Dockerfile instead: | ||
# https://github.com/microsoft/vscode-dev-containers/tree/v0.100.0/containers/ubuntu-18.04-git/.devcontainer/Dockerfile | ||
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:12 | ||
|
||
ENV PATH /root/.cargo/bin:/root/emsdk/upstream/bin:$PATH | ||
|
||
# Install Rust | ||
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y | ||
RUN cargo install wasm-pack | ||
|
||
# Install emsdk | ||
RUN cd /root \ | ||
&& git clone https://github.com/emscripten-core/emsdk.git \ | ||
&& cd emsdk \ | ||
&& ./emsdk install latest | ||
|
||
|
||
# Install benchmark util | ||
RUN npm i -g @c4312/matcha |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at: | ||
// https://github.com/microsoft/vscode-dev-containers/tree/v0.100.0/containers/ubuntu-18.04-git | ||
{ | ||
"name": "Ubuntu 18.04 & Git", | ||
"dockerFile": "Dockerfile", | ||
|
||
// Set *default* container specific settings.json values on container create. | ||
"settings": { | ||
"terminal.integrated.shell.linux": "/bin/bash" | ||
}, | ||
|
||
// Add the IDs of extensions you want installed when the container is created. | ||
"extensions": [] | ||
|
||
// Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
// "forwardPorts": [], | ||
|
||
// Use 'postCreateCommand' to run commands after the container is created. | ||
// "postCreateCommand": "uname -a", | ||
|
||
// Uncomment to use the Docker CLI from inside the container. See https://aka.ms/vscode-remote/samples/docker-in-docker. | ||
// "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ], | ||
|
||
// Uncomment when using a ptrace-based debugger like C++, Go, and Rust | ||
// "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ], | ||
|
||
// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root. | ||
// "remoteUser": "vscode" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* | ||
!/pkg | ||
!/index.js | ||
!/index.d.ts |
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 |
---|---|---|
|
@@ -9,5 +9,4 @@ crate-type = ["cdylib"] | |
|
||
[dependencies] | ||
wasm-bindgen = "0.2" | ||
encoding = "0.2" | ||
|
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export function hash(input: Buffer): string; |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const { hash } = require('./pkg/chromehash'); | ||
|
||
const output = Buffer.alloc(4 * 5); | ||
|
||
exports.hash = input => { | ||
hash(normalize(input), output); | ||
return output.toString('hex'); | ||
}; | ||
|
||
const hasUTF8BOM = buffer => | ||
buffer.length >= 3 && buffer[0] === 0xef && buffer[1] === 0xbb && buffer[2] === 0xbf; | ||
const hasUtf16LEBOM = buffer => buffer.length >= 2 && buffer[0] === 0xff && buffer[1] === 0xfe; | ||
const hasUtf16BEBOM = buffer => buffer.length >= 2 && buffer[0] === 0xfe && buffer[1] === 0xff; | ||
|
||
const normalize = buffer => { | ||
if (hasUTF8BOM(buffer)) { | ||
return utf8ToUtf16(buffer.slice(3)); | ||
} | ||
|
||
if (hasUtf16LEBOM(buffer)) { | ||
return buffer.slice(2); | ||
} | ||
|
||
if (hasUtf16BEBOM(buffer)) { | ||
return buffer.slice(2).swap16(); | ||
} | ||
|
||
return utf8ToUtf16(buffer); | ||
} | ||
|
||
const utf8ToUtf16 = buffer => Buffer.from(buffer.toString('utf8'), 'utf16le'); | ||
|
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