Skip to content

Commit

Permalink
Revert "fix: kv:key put upload binary files fix (#1255)"
Browse files Browse the repository at this point in the history
This reverts commit 2d806dc.
  • Loading branch information
threepointone committed Jun 17, 2022
1 parent d81ae5a commit 1b068c9
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 45 deletions.
5 changes: 5 additions & 0 deletions .changeset/wild-toes-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Revert "fix: kv:key put upload binary files fix (#1255)"
25 changes: 2 additions & 23 deletions packages/wrangler/src/__tests__/kv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,11 +448,10 @@ describe("wrangler", () => {
});

it("should put a key with a value loaded from a given path", async () => {
const buf = Buffer.from("file-contents", "utf-8");
writeFileSync("foo.txt", buf);
writeFileSync("foo.txt", "file-contents", "utf-8");
const requests = mockKeyPutRequest("some-namespace-id", {
key: "my-key",
value: buf,
value: "file-contents",
});
await runWrangler(
"kv:key put my-key --namespace-id some-namespace-id --path foo.txt"
Expand All @@ -464,26 +463,6 @@ describe("wrangler", () => {
expect(requests.count).toEqual(1);
});

it("should put a key with a binary value loaded from a given path", async () => {
const buf = Buffer.from(
"iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAiSURBVHgB7coxEQAACMPAgH/PgAM6dGwu49fA/deIBXrgAj2cAhIFT4QxAAAAAElFTkSuQmCC",
"base64"
);
writeFileSync("test.png", buf);
const requests = mockKeyPutRequest("another-namespace-id", {
key: "my-key",
value: buf,
});
await runWrangler(
"kv:key put my-key --namespace-id another-namespace-id --path test.png"
);
expect(std.out).toMatchInlineSnapshot(
`"Writing the contents of test.png to the key \\"my-key\\" on namespace another-namespace-id."`
);
expect(std.err).toMatchInlineSnapshot(`""`);
expect(requests.count).toEqual(1);
});

it("should error if no key is provided", async () => {
await expect(
runWrangler("kv:key put")
Expand Down
3 changes: 1 addition & 2 deletions packages/wrangler/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import {
parsePackageJSON,
parseTOML,
readFileSync,
readFileSyncToBuffer,
} from "./parse";
import publish from "./publish";
import { createR2Bucket, deleteR2Bucket, listR2Buckets } from "./r2";
Expand Down Expand Up @@ -2273,7 +2272,7 @@ function createCLIParser(argv: string[]) {
const namespaceId = getKVNamespaceId(args, config);
// One of `args.path` and `args.value` must be defined
const value = args.path
? readFileSyncToBuffer(args.path)
? readFileSync(args.path)
: // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
args.value!;

Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/kv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export async function deleteKVNamespace(
*/
export interface KeyValue {
key: string;
value: string | Buffer;
value: string;
expiration?: number;
expiration_ttl?: number;
metadata?: object;
Expand Down
19 changes: 0 additions & 19 deletions packages/wrangler/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,25 +139,6 @@ export function parseJSON<T>(input: string, file?: string): T {
}
}

/**
* Reads a file into a node Buffer.
*/
export function readFileSyncToBuffer(file: string): Buffer {
try {
return fs.readFileSync(file);
} catch (err) {
const { message } = err as Error;
throw new ParseError({
text: `Could not read file: ${file}`,
notes: [
{
text: message.replace(file, resolve(file)),
},
],
});
}
}

/**
* Reads a file and parses it based on its type.
*/
Expand Down

0 comments on commit 1b068c9

Please sign in to comment.