-
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
Showing
6 changed files
with
191 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
.DS_Store | ||
env | ||
env.swap | ||
node_modules |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"lockfileVersion": 1, | ||
"workspaces": { | ||
"": { | ||
"name": "bun-s3", | ||
"dependencies": { | ||
"yargs": "^17.7.2", | ||
}, | ||
"devDependencies": { | ||
"@types/bun": "latest", | ||
}, | ||
}, | ||
}, | ||
"packages": { | ||
"@types/bun": ["@types/[email protected]", "", { "dependencies": { "bun-types": "1.2.1" } }, "sha512-iiCeMAKMkft8EPQJxSbpVRD0DKqrh91w40zunNajce3nMNNFd/LnAquVisSZC+UpTMjDwtcdyzbWct08IvEqRA=="], | ||
|
||
"@types/node": ["@types/[email protected]", "", { "dependencies": { "undici-types": "~6.20.0" } }, "sha512-Fll2FZ1riMjNmlmJOdAyY5pUbkftXslB5DgEzlIuNaiWhXd00FhWxVC/r4yV/4wBb9JfImTu+jiSvXTkJ7F/gA=="], | ||
|
||
"@types/ws": ["@types/[email protected]", "", { "dependencies": { "@types/node": "*" } }, "sha512-bd/YFLW+URhBzMXurx7lWByOu+xzU9+kb3RboOteXYDfW+tr+JZa99OyNmPINEGB/ahzKrEuc8rcv4gnpJmxTw=="], | ||
|
||
"ansi-regex": ["[email protected]", "", {}, "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ=="], | ||
|
||
"ansi-styles": ["[email protected]", "", { "dependencies": { "color-convert": "^2.0.1" } }, "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg=="], | ||
|
||
"bun-types": ["[email protected]", "", { "dependencies": { "@types/node": "*", "@types/ws": "~8.5.10" } }, "sha512-p7bmXUWmrPWxhcbFVk7oUXM5jAGt94URaoa3qf4mz43MEhNAo/ot1urzBqctgvuq7y9YxkuN51u+/qm4BiIsHw=="], | ||
|
||
"cliui": ["[email protected]", "", { "dependencies": { "string-width": "^4.2.0", "strip-ansi": "^6.0.1", "wrap-ansi": "^7.0.0" } }, "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ=="], | ||
|
||
"color-convert": ["[email protected]", "", { "dependencies": { "color-name": "~1.1.4" } }, "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ=="], | ||
|
||
"color-name": ["[email protected]", "", {}, "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="], | ||
|
||
"emoji-regex": ["[email protected]", "", {}, "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A=="], | ||
|
||
"escalade": ["[email protected]", "", {}, "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA=="], | ||
|
||
"get-caller-file": ["[email protected]", "", {}, "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg=="], | ||
|
||
"is-fullwidth-code-point": ["[email protected]", "", {}, "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg=="], | ||
|
||
"require-directory": ["[email protected]", "", {}, "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q=="], | ||
|
||
"string-width": ["[email protected]", "", { "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", "strip-ansi": "^6.0.1" } }, "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g=="], | ||
|
||
"strip-ansi": ["[email protected]", "", { "dependencies": { "ansi-regex": "^5.0.1" } }, "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A=="], | ||
|
||
"undici-types": ["[email protected]", "", {}, "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg=="], | ||
|
||
"wrap-ansi": ["[email protected]", "", { "dependencies": { "ansi-styles": "^4.0.0", "string-width": "^4.1.0", "strip-ansi": "^6.0.0" } }, "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q=="], | ||
|
||
"y18n": ["[email protected]", "", {}, "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA=="], | ||
|
||
"yargs": ["[email protected]", "", { "dependencies": { "cliui": "^8.0.1", "escalade": "^3.1.1", "get-caller-file": "^2.0.5", "require-directory": "^2.1.1", "string-width": "^4.2.3", "y18n": "^5.0.5", "yargs-parser": "^21.1.1" } }, "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w=="], | ||
|
||
"yargs-parser": ["[email protected]", "", {}, "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw=="], | ||
} | ||
} |
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,11 @@ | ||
{ | ||
"name": "bun-s3", | ||
"module": "index.ts", | ||
"type": "module", | ||
"devDependencies": { | ||
"@types/bun": "latest" | ||
}, | ||
"dependencies": { | ||
"yargs": "^17.7.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,94 @@ | ||
#!/usr/bin/env bun | ||
import { $, S3Client, type S3File } from "bun"; | ||
import { hideBin } from "yargs/helpers"; | ||
import yargs from "yargs/yargs"; | ||
|
||
function createClient(file: string) { | ||
const url = new URL(file); | ||
const bucket = url.pathname.split("/")[1]; | ||
const endpoint = `https://${url.hostname}`; | ||
|
||
return new S3Client({ | ||
accessKeyId: Bun.env.AWS_ACCESS_KEY_ID, | ||
secretAccessKey: Bun.env.AWS_SECRET_ACCESS_KEY, | ||
region: Bun.env.AWS_DEFAULT_REGION, | ||
bucket, | ||
endpoint, | ||
}); | ||
} | ||
|
||
function objectPath(file: string) { | ||
return new URL(file).pathname.split("/").slice(2).join("/"); | ||
} | ||
|
||
yargs(hideBin(process.argv)) | ||
.command( | ||
"cat file", | ||
"cat file", | ||
(yargs) => { | ||
yargs.positional("file", { describe: "file path" }); | ||
yargs.option("encrypt", { | ||
alias: "e", | ||
describe: "file is encrypted", | ||
}); | ||
}, | ||
async (args) => { | ||
const client = createClient(args.file); | ||
const path = objectPath(args.file); | ||
const s3file: S3File = client.file(path); | ||
const text = await s3file.text(); | ||
Bun.stdout.write(text); | ||
}, | ||
) | ||
.command( | ||
"pull file [dest]", | ||
"pull file [dest]", | ||
(yargs) => { | ||
yargs.positional("file", { | ||
describe: "file path", | ||
}); | ||
yargs.option("encrypt", { | ||
alias: "e", | ||
describe: "file is encrypted", | ||
}); | ||
}, | ||
async (args) => { | ||
const client = createClient(args.file); | ||
const path = objectPath(args.file); | ||
const s3file: S3File = client.file(path); | ||
const name = args.dest ?? path; | ||
await Bun.write(name, s3file); | ||
}, | ||
) | ||
.command( | ||
"push file [dest]", | ||
"push file [dest]", | ||
(yargs) => { | ||
yargs.positional("file", { | ||
describe: "file path", | ||
}); | ||
yargs.option("encrypt", { | ||
alias: "e", | ||
describe: "encrypt the file", | ||
}); | ||
}, | ||
async (args) => { | ||
const file = Bun.file(args.file); | ||
const arrbuf = await file.arrayBuffer(); | ||
const buffer = Buffer.from(arrbuf); | ||
|
||
if (args.encrypt) { | ||
// use openssl to encrypt the file | ||
// openssl enc -aes-256-cbc -salt -pbkdf2 -in $1 -out $1.enc $2 | ||
} | ||
|
||
// const client = createClient(args.dest); | ||
// const path = objectPath(args.dest); | ||
// const s3file: S3File = client.file(path); | ||
|
||
// await s3file.write(buffer); | ||
}, | ||
) | ||
.strictCommands() | ||
.demandCommand(1) | ||
.parse(); |
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,27 @@ | ||
{ | ||
"compilerOptions": { | ||
// Enable latest features | ||
"lib": ["ESNext", "DOM"], | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"moduleDetection": "force", | ||
"jsx": "react-jsx", | ||
"allowJs": true, | ||
|
||
// Bundler mode | ||
"moduleResolution": "bundler", | ||
"allowImportingTsExtensions": true, | ||
"verbatimModuleSyntax": true, | ||
"noEmit": true, | ||
|
||
// Best practices | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"noFallthroughCasesInSwitch": true, | ||
|
||
// Some stricter flags (disabled by default) | ||
"noUnusedLocals": false, | ||
"noUnusedParameters": false, | ||
"noPropertyAccessFromIndexSignature": false | ||
} | ||
} |