Skip to content

Commit

Permalink
fix(file): encode absolute path for variable name
Browse files Browse the repository at this point in the history
  • Loading branch information
Curve committed Oct 25, 2024
1 parent b8d7fd2 commit 1c62b47
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@saucer-dev/cli",
"version": "6.1.0",
"version": "6.1.1",
"license": "MIT",
"description": "🛸 A command-line utility for saucer",
"author": "Curve (https://github.com/Curve)",
Expand Down Expand Up @@ -28,7 +28,7 @@
"build"
],
"dependencies": {
"base62": "^2.0.2",
"base-x": "^5.0.0",
"commander": "^12.1.0",
"eslint-plugin-neverthrow": "^1.1.4",
"eta": "^3.5.0",
Expand Down
13 changes: 6 additions & 7 deletions pnpm-lock.yaml

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

6 changes: 4 additions & 2 deletions src/file.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import base62 from "base62";
import basex from "base-x";
import { exists } from "fs-extra";
import { lstat, readFile } from "fs/promises";
import mimes from "mime-types";
Expand All @@ -13,6 +13,8 @@ export interface File
size: number;
}

const base62 = basex("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");

export async function parse(absolute: string, relative: string): Promise<Result<File, string>>
{
if (!await exists(absolute))
Expand Down Expand Up @@ -40,7 +42,7 @@ export async function parse(absolute: string, relative: string): Promise<Result<
}

const path = relative.replace(/\\/g, "/");
const name = `f${base62.encode(parseInt([...relative].map(x => x.charCodeAt(0)).join("")))}`;
const name = `f${base62.encode(Buffer.from(absolute))}`;

const size = stream.value.byteLength;
const data = [...stream.value].map(b => `0x${b.toString(16)}`).join(", ");
Expand Down

0 comments on commit 1c62b47

Please sign in to comment.