-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ecf739d
commit a3a0c5a
Showing
1 changed file
with
34 additions
and
11 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 |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import { readAllSync } from "https://deno.land/[email protected]/streams/conversion.ts"; | ||
import { getStdinBufferSync } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { Command } from "https://deno.land/x/[email protected]/command/mod.ts"; | ||
import { base85encode, base85decode } from "./mod.ts"; | ||
import { version } from "./version.ts"; | ||
// deno-lint-ignore-file camelcase no-dupe-else-if | ||
import { | ||
base85decode, | ||
base85encode, | ||
Command, | ||
getStdinBufferSync, | ||
readAllSync, | ||
version, | ||
} from "./deps.ts"; | ||
|
||
try { | ||
let file: Uint8Array; | ||
|
@@ -35,7 +39,9 @@ try { | |
} | ||
} | ||
} else if (Deno.args[0] !== undefined) { | ||
args_judge = Deno.args[0].match(/-d|--decode|-h|--help|-V|--version/) ? true : false; | ||
args_judge = Deno.args[0].match(/-d|--decode|-h|--help|-V|--version/) | ||
? true | ||
: false; | ||
if (!args_judge) { | ||
try { | ||
file = readAllSync(Deno.openSync(Deno.args[0])); | ||
|
@@ -56,18 +62,35 @@ try { | |
} | ||
const { options, args } = await new Command() | ||
.name("base85") | ||
.description("Base85 (Ascii85 with Adobe Escape Sequence) encode or decode FILE, or standard input, to standard output.") | ||
.description( | ||
"Base85 (Ascii85 with Adobe Escape Sequence) encode or decode FILE, or standard input, to standard output.", | ||
) | ||
.version(version()) | ||
.option("-d, --decode", "Decode data") | ||
.arguments("<option>") | ||
.parse(!isatty ? (args_judge! ? [[...stdin!].join(",")] : [Deno.args[0], [...stdin!].join(",")].filter(Boolean)) : !file! ? Deno.args : !args_judge! ? [[...file!].join(",")] : [Deno.args[0], [...file!].join(",")]); | ||
.parse( | ||
!isatty | ||
? (args_judge! | ||
? [[...stdin!].join(",")] | ||
: [Deno.args[0], [...stdin!].join(",")].filter(Boolean)) | ||
: !file! | ||
? Deno.args | ||
: !args_judge! | ||
? [[...file!].join(",")] | ||
: [Deno.args[0], [...file!].join(",")], | ||
); | ||
const { decode } = options; | ||
const runner: ((str: string) => Uint8Array) | ((byte: Uint8Array) => string) = decode ? base85decode : base85encode; | ||
const runner: ((str: string) => Uint8Array) | ((byte: Uint8Array) => string) = | ||
decode ? base85decode : base85encode; | ||
const convert: () => void = (): void => { | ||
const args2Unit8Array: Uint8Array = new Uint8Array(args[0].split(",")); | ||
const input: Uint8Array | string = decode ? new TextDecoder().decode(args2Unit8Array).replace(/\n$/g, "") : args2Unit8Array; | ||
const input: Uint8Array | string = decode | ||
? new TextDecoder().decode(args2Unit8Array).replace(/\n$/g, "") | ||
: args2Unit8Array; | ||
const result: string | Uint8Array = runner(input! as Uint8Array & string); | ||
typeof result === "string" ? console.log(result) : Deno.stdout.writeSync(result); | ||
typeof result === "string" | ||
? console.log(result) | ||
: Deno.stdout.writeSync(result); | ||
}; | ||
if (filled!) { | ||
convert(); | ||
|