Skip to content

Commit

Permalink
1.2.1 Upgrade base128-ascii
Browse files Browse the repository at this point in the history
  • Loading branch information
bddjr committed Jan 8, 2025
1 parent 0d2f2b2 commit 561c9fb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite-plugin-singlefile-compression",
"version": "1.2.0",
"version": "1.2.1",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
Expand Down Expand Up @@ -42,7 +42,7 @@
"dependencies": {
"@types/html-minifier-terser": "^7.0.2",
"@types/node": "^22.9.3",
"base128-ascii": "^0.0.1",
"base128-ascii": "^1.0.0",
"esbuild": "^0.24.0",
"html-minifier-terser": "^7.2.0",
"mime": "^4.0.4",
Expand Down
13 changes: 7 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,19 @@ function bufferToDataURL(name: string, b: Buffer) {
: `data:${mime.getType(name)};base64,${b.toString('base64')}`
}

function gzipToBase64(buf: zlib.InputType) {
function gzip(buf: zlib.InputType) {
return zlib.gzipSync(buf, {
level: zlib.constants.Z_BEST_COMPRESSION,
}).toString('base64')
})
}

function gzipToBase128(buf: zlib.InputType) {
return base128.encodeToTemplateLiterals(Uint8Array.from(zlib.gzipSync(buf, {
level: zlib.constants.Z_BEST_COMPRESSION,
})))
function gzipToBase64(buf: zlib.InputType) {
return gzip(buf).toString('base64')
}

function gzipToBase128(buf: zlib.InputType) {
return base128.encode(Uint8Array.from(gzip(buf))).toJSTemplateLiterals()
}

function KiB(size: number) {
return `${Math.ceil(size / 10.24) / 100} KiB`
Expand Down

0 comments on commit 561c9fb

Please sign in to comment.