@storecraft/storage-s3-compatible 1.0.16 → 1.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storecraft/storage-s3-compatible",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "description": "Official S3-Compatible Storage adapter for storecraft",
5
5
  "license": "MIT",
6
6
  "author": "Tomer Shalev (https://github.com/store-craft)",
@@ -5,10 +5,21 @@ import { readFile } from 'node:fs/promises';
5
5
  import { storage as storage_test_runner } from '@storecraft/core/test-runner'
6
6
 
7
7
 
8
+ /**
9
+ * @param {Blob} blob1
10
+ * @param {Blob} blob2
11
+ */
8
12
  const areBlobsEqual = async (blob1, blob2) => {
9
- return !Buffer.from(await blob1.arrayBuffer()).compare(
10
- Buffer.from(await blob2.arrayBuffer())
11
- );
13
+ const array1 = new Uint8Array(await blob1.arrayBuffer());
14
+ const array2 = new Uint8Array(await blob2.arrayBuffer());
15
+
16
+ if (array1.length !== array2.length) return false;
17
+
18
+ for (let i = 0; i < array1.length; i++) {
19
+ if (array1[i] !== array2[i]) return false;
20
+ }
21
+
22
+ return true;
12
23
  };
13
24
 
14
25
  const storage = new R2({
@@ -22,6 +33,12 @@ const suite = storage_test_runner.create(storage);
22
33
 
23
34
  suite.before(async () => { await storage.init(undefined) });
24
35
 
36
+ suite('bad get', async () => {
37
+ const v = await storage.getBlob('i-dont-exist.png');
38
+ assert.not(v.value, 'should not exist');
39
+ });
40
+
41
+
25
42
  suite('blob put/get/delete', async () => {
26
43
  const data = [
27
44
  {
@@ -61,7 +78,9 @@ suite('blob put (presign)', async () => {
61
78
  data.forEach(
62
79
  async d => {
63
80
  // get put presigned url
64
- const { url, method, headers } = await storage.putSigned(d.key);
81
+ const {
82
+ url, method, headers
83
+ } = await storage.putSigned(d.key);
65
84
  // now let's use it to upload
66
85
  const r = await fetch(
67
86
  url, {
@@ -71,9 +90,29 @@ suite('blob put (presign)', async () => {
71
90
  }
72
91
  );
73
92
 
74
- console.log(url)
75
-
76
93
  assert.ok(r.ok, 'upload failed')
94
+
95
+ { // now let's read it back, once with presigned url
96
+ const {
97
+ method, url, headers
98
+ } = await storage.getSigned(d.key);
99
+ const r_get = await fetch(
100
+ url, {
101
+ method,
102
+ headers,
103
+ }
104
+ );
105
+
106
+ // compare
107
+ const equal = await areBlobsEqual(await r_get.blob(), d.blob);
108
+ assert.ok(equal, 'Blobs are not equal when compared with presigned get !!!');
109
+ }
110
+ { // now let's read it back with normal get
111
+ const { value: blob_read } = await storage.getBlob(d.key);
112
+ // compare
113
+ const equal = await areBlobsEqual(blob_read, d.blob);
114
+ assert.ok(equal, 'Blobs are not equal with regular get !!!');
115
+ }
77
116
  }
78
117
  );
79
118