MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / awsUriEncode

Function awsUriEncode

packages/filesystem/s3/client.ts:59–81  ·  view source on GitHub ↗

AWS Signature V4 要求的 URI 编码,仅保留 A-Za-z0-9_-.~ 不编码

(str: string, encodeSlash: boolean = true)

Source from the content-addressed store, hash-verified

57
58/** AWS Signature V4 要求的 URI 编码,仅保留 A-Za-z0-9_-.~ 不编码 */
59function awsUriEncode(str: string, encodeSlash: boolean = true): string {
60 let result = "";
61 const bytes = new TextEncoder().encode(str);
62 for (const b of bytes) {
63 const ch = String.fromCharCode(b);
64 if (
65 (ch >= "A" && ch <= "Z") ||
66 (ch >= "a" && ch <= "z") ||
67 (ch >= "0" && ch <= "9") ||
68 ch === "_" ||
69 ch === "-" ||
70 ch === "~" ||
71 ch === "."
72 ) {
73 result += ch;
74 } else if (ch === "/" && !encodeSlash) {
75 result += ch;
76 } else {
77 result += `%${b.toString(16).toUpperCase().padStart(2, "0")}`;
78 }
79 }
80 return result;
81}
82
83// ---- S3 错误处理 ----
84

Callers 3

getCanonicalUriMethod · 0.85
buildUrlMethod · 0.85
signRequestMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected