Skip to content

Commit

Permalink
Fix the incorrect process of converting ArrayBuffer to base64 (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
Karibash authored Aug 25, 2023
1 parent 2725345 commit 803dd41
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/popular-cheetahs-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'cf-bindings-proxy': patch
---

Fix the incorrect process of converting ArrayBuffer to base64
2 changes: 1 addition & 1 deletion src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const preparePropertyCallArg = async (
): Promise<PropertyCall['args'][0]> => {
if (arg.data instanceof ArrayBuffer) {
return {
data: transformData(arg, { from: 'buffer', to: 'base64' }),
data: transformData(arg.data, { from: 'buffer', to: 'base64' }),
transform: { from: 'base64', to: 'buffer' },
};
}
Expand Down
10 changes: 8 additions & 2 deletions tests/proxy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,15 @@ suite('bindings', () => {
const firstFile = await binding<R2Bucket>('R2').put('first-key', new ArrayBuffer(1), {
customMetadata: { source: 'test-suite', v: '1' },
});
const secondFile = await binding<R2Bucket>('R2').put('second-key', new ArrayBuffer(1), {
const secondFile = await binding<R2Bucket>('R2').put('second-key', new ArrayBuffer(2), {
customMetadata: { source: 'test-suite', v: '2' },
});

expect(firstFile.key).toEqual('first-key');
expect(firstFile.size).toEqual(1);

expect(secondFile.key).toEqual('second-key');
expect(secondFile.size).toEqual(2);
});

test('put -> Blob', async () => {
Expand All @@ -262,14 +265,17 @@ suite('bindings', () => {
);
const secondFile = await binding<R2Bucket>('R2').put(
'second-key',
new Blob([new ArrayBuffer(1)]),
new Blob([new ArrayBuffer(2)]),
{
customMetadata: { source: 'test-suite', v: '2' },
},
);

expect(firstFile.key).toEqual('first-key');
expect(firstFile.size).toEqual(1);

expect(secondFile.key).toEqual('second-key');
expect(secondFile.size).toEqual(2);
});

test('get', async () => {
Expand Down

0 comments on commit 803dd41

Please sign in to comment.