@gjsify/buffer 0.0.2

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/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # @gjsify/buffer
2
+
3
+ Node.js buffer module for Gjs
4
+
5
+ ## Inspirations and credits
6
+ - https://deno.land/std/node/buffer.ts
7
+ - https://github.com/feross/buffer
@@ -0,0 +1,36 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var src_exports = {};
30
+ __export(src_exports, {
31
+ default: () => src_default
32
+ });
33
+ module.exports = __toCommonJS(src_exports);
34
+ __reExport(src_exports, require("@gjsify/deno_std/node/buffer"), module.exports);
35
+ var import_buffer = __toESM(require("@gjsify/deno_std/node/buffer"), 1);
36
+ var src_default = import_buffer.default;
@@ -0,0 +1,6 @@
1
+ export * from "@gjsify/deno_std/node/buffer";
2
+ import buffer from "@gjsify/deno_std/node/buffer";
3
+ var src_default = buffer;
4
+ export {
5
+ src_default as default
6
+ };
@@ -0,0 +1,3 @@
1
+ export * from '@gjsify/deno_std/node/buffer';
2
+ import buffer from '@gjsify/deno_std/node/buffer';
3
+ export default buffer;
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@gjsify/buffer",
3
+ "version": "0.0.2",
4
+ "description": "Node.js buffer module for Gjs",
5
+ "type": "module",
6
+ "main": "lib/cjs/index.js",
7
+ "module": "lib/esm/index.js",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./lib/types/index.d.ts",
12
+ "default": "./lib/esm/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./lib/types/index.d.ts",
16
+ "default": "./lib/cjs/index.js"
17
+ }
18
+ }
19
+ },
20
+ "scripts": {
21
+ "clear": "rm -rf lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo || exit 0",
22
+ "print:name": "echo '@gjsify/buffer'",
23
+ "build": "yarn print:name && yarn build:gjsify && yarn build:types",
24
+ "build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
25
+ "build:types": "tsc --project tsconfig.types.json || exit 0",
26
+ "build:test": "yarn build:test:gjs && yarn build:test:node",
27
+ "build:test:gjs": "gjsify build src/test.mts --app gjs --outfile test.gjs.mjs",
28
+ "build:test:node": "gjsify build src/test.mts --app node --outfile test.node.mjs",
29
+ "test": "yarn print:name && yarn build:gjsify && yarn build:test && yarn test:node && yarn test:gjs",
30
+ "test:gjs": "gjs -m test.gjs.mjs",
31
+ "test:node": "node test.node.mjs"
32
+ },
33
+ "keywords": [
34
+ "gjs",
35
+ "node",
36
+ "buffer"
37
+ ],
38
+ "devDependencies": {
39
+ "@gjsify/cli": "^0.0.2",
40
+ "@gjsify/unit": "^0.0.2",
41
+ "@types/node": "^20.3.1",
42
+ "typescript": "^5.1.3"
43
+ },
44
+ "dependencies": {
45
+ "@gjsify/deno_std": "^0.0.2"
46
+ }
47
+ }
@@ -0,0 +1,583 @@
1
+ import { describe, it, expect } from '@gjsify/unit';
2
+ import { Buffer } from 'buffer';
3
+
4
+ export default async () => {
5
+
6
+ // Tests ported from https://github.com/denoland/deno_std/blob/main/node/buffer_test.ts
7
+
8
+ await describe('alloc fails if size is not a number', async () => {
9
+ const invalidSizes = [{}, "1", "foo", []];
10
+
11
+ await it('should throw on non-number size', async () => {
12
+ for (const size of invalidSizes) {
13
+ expect(() => {
14
+ // deno-lint-ignore ban-ts-comment
15
+ // @ts-expect-error
16
+ Buffer.alloc(size);
17
+ }).toThrow(TypeError);
18
+ }
19
+ });
20
+ });
21
+
22
+
23
+ await describe('alloc allocates a buffer with the expected size', async () => {
24
+ const buffer: Buffer = Buffer.alloc(1);
25
+ await it('Buffer size should be 1', async () => {
26
+ expect(buffer.length).toBe(1);
27
+ });
28
+ await it('Content should be filled with 0', async () => {
29
+ expect(buffer[0]).toBe(0);
30
+ });
31
+ });
32
+
33
+ await describe('alloc(0) creates an empty buffer', async () => {
34
+ const buffer: Buffer = Buffer.alloc(0);
35
+ await it('Buffer size should be 0', async () => {
36
+ expect(buffer.length).toBe(0);
37
+ });
38
+ });
39
+
40
+ await describe('allocUnsafe allocates a buffer with the expected size', async () => {
41
+ const buffer: Buffer = Buffer.allocUnsafe(1);
42
+ await it('Buffer size should be 1', async () => {
43
+ expect(buffer.length).toBe(1);
44
+ });
45
+ });
46
+
47
+ await describe('allocUnsafe(0) creates an empty buffer', async () => {
48
+ const buffer: Buffer = Buffer.allocUnsafe(0);
49
+ await it('Buffer size should be 0', async () => {
50
+ expect(buffer.length).toBe(0);
51
+ });
52
+ });
53
+
54
+ await describe('alloc filled correctly with integer', async () => {
55
+ const buffer: Buffer = Buffer.alloc(3, 5);
56
+ await it('Should be equal to `Buffer.from([5, 5, 5])`', async () => {
57
+ expect(buffer).toEqualArray(Buffer.from([5, 5, 5]));
58
+ });
59
+ });
60
+
61
+ await describe('alloc filled correctly with single character', async () => {
62
+ await it('Should be equal to `Buffer.from([97, 97, 97, 97, 97])`', async () => {
63
+ expect(Buffer.alloc(5, "a")).toEqualArray(Buffer.from([97, 97, 97, 97, 97]));
64
+ });
65
+ });
66
+
67
+ await describe('alloc filled correctly with base64 string', async () => {
68
+ await it('Should be equal to `Buffer.from([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100])`', async () => {
69
+ expect(Buffer.alloc(11, "aGVsbG8gd29ybGQ=", "base64")).toEqualArray(Buffer.from([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]));
70
+ });
71
+ });
72
+
73
+ await describe('alloc filled correctly with hex string', async () => {
74
+ await it('Should be equal to `Buffer.from([100, 101, 110, 111])`', async () => {
75
+ expect(Buffer.alloc(4, "64656e6f", "hex")).toEqualArray(Buffer.from([100, 101, 110, 111]));
76
+ });
77
+ });
78
+
79
+ await describe('alloc filled correctly with hex string smaller than alloc size', async () => {
80
+ await it('Should be equal to `denodenodenod`', async () => {
81
+ expect(Buffer.alloc(13, "64656e6f", "hex").toString()).toEqual("denodenodenod");
82
+ });
83
+ });
84
+
85
+ await describe('alloc filled correctly with Uint8Array smaller than alloc size', async () => {
86
+ await it('Should be equal to `Buffer.from([100, 101, 100, 101, 100, 101, 100])`', async () => {
87
+ expect(Buffer.alloc(7, new Uint8Array([100, 101]) as any)).toEqualArray(Buffer.from([100, 101, 100, 101, 100, 101, 100]));
88
+ });
89
+ await it('Should be equal to `Buffer.from([100, 101, 100, 101, 100, 101])`', async () => {
90
+ expect(Buffer.alloc(6, new Uint8Array([100, 101]) as any)).toEqualArray(Buffer.from([100, 101, 100, 101, 100, 101]));
91
+ });
92
+ });
93
+
94
+ await describe('alloc filled correctly with Uint8Array bigger than alloc size', async () => {
95
+ await it('Should be equal to `Buffer.from([100])`', async () => {
96
+ expect(Buffer.alloc(1, new Uint8Array([100, 101]) as any)).toEqualArray(Buffer.from([100]));
97
+ });
98
+ });
99
+
100
+ await describe('alloc filled correctly with Buffer', async () => {
101
+ await it('Should be equal to `Buffer.from([100, 101, 100, 101, 100, 101])`', async () => {
102
+ expect(Buffer.alloc(6, Buffer.from([100, 101]))).toEqualArray(Buffer.from([100, 101, 100, 101, 100, 101]));
103
+ });
104
+
105
+ await it('Should be equal to `Buffer.from([100, 101, 100, 101, 100, 101, 100])`', async () => {
106
+ expect(Buffer.alloc(7, Buffer.from([100, 101]))).toEqualArray(Buffer.from([100, 101, 100, 101, 100, 101, 100]));
107
+ });
108
+ });
109
+
110
+ // tests from:
111
+ // https://github.com/nodejs/node/blob/56dbe466fdbc598baea3bfce289bf52b97b8b8f7/test/parallel/test-buffer-bytelength.js#L70
112
+ await describe('Buffer.byteLength()', async () => {
113
+ await it('Byte length is the expected for strings`', async () => {
114
+ // Special case: zero length string
115
+ expect(Buffer.byteLength("", "ascii")).toBe(0);
116
+ expect(Buffer.byteLength("", "HeX" as any)).toBe(0);
117
+
118
+ // utf8
119
+ expect(Buffer.byteLength("∑éllö wørl∂!", "utf-8")).toBe(19);
120
+ expect(Buffer.byteLength("κλμνξο", "utf8")).toBe(12);
121
+ expect(Buffer.byteLength("挵挶挷挸挹", "utf-8")).toBe(15);
122
+ expect(Buffer.byteLength("𠝹𠱓𠱸", "UTF8" as any)).toBe(12);
123
+ // Without an encoding, utf8 should be assumed
124
+ expect(Buffer.byteLength("hey there")).toBe(9);
125
+ expect(Buffer.byteLength("𠱸挶νξ#xx :)")).toBe(17);
126
+ expect(Buffer.byteLength("hello world", "" as any)).toBe(11);
127
+ // It should also be assumed with unrecognized encoding
128
+ expect(Buffer.byteLength("hello world", "abc" as any)).toBe(11);
129
+ expect(Buffer.byteLength("ßœ∑≈", "unkn0wn enc0ding" as any)).toBe(10);
130
+
131
+ // base64
132
+ expect(Buffer.byteLength("aGVsbG8gd29ybGQ=", "base64")).toBe(11);
133
+ expect(Buffer.byteLength("aGVsbG8gd29ybGQ=", "BASE64" as any)).toBe(11);
134
+ expect(Buffer.byteLength("bm9kZS5qcyByb2NrcyE=", "base64")).toBe(14);
135
+ expect(Buffer.byteLength("aGkk", "base64")).toBe(3);
136
+ expect(
137
+ Buffer.byteLength("bHNrZGZsa3NqZmtsc2xrZmFqc2RsZmtqcw==", "base64")).toBe(25);
138
+ // special padding
139
+ expect(Buffer.byteLength("aaa=", "base64")).toBe(2);
140
+ expect(Buffer.byteLength("aaaa==", "base64")).toBe(3);
141
+
142
+ expect(Buffer.byteLength("Il était tué")).toBe(14);
143
+ expect(Buffer.byteLength("Il était tué", "utf8")).toBe(14);
144
+
145
+ ["ascii", "latin1", "binary"]
146
+ .reduce((es: string[], e: string) => es.concat(e, e.toUpperCase()), [])
147
+ .forEach((encoding: BufferEncoding) => {
148
+ expect(Buffer.byteLength("Il était tué", encoding)).toBe(12);
149
+ });
150
+
151
+ ["ucs2", "ucs-2", "utf16le", "utf-16le"]
152
+ .reduce((es: string[], e: string) => es.concat(e, e.toUpperCase()), [])
153
+ .forEach((encoding: BufferEncoding) => {
154
+ expect(Buffer.byteLength("Il était tué", encoding)).toBe(24);
155
+ });
156
+ });
157
+ });
158
+
159
+ await describe('Byte length is the expected one for non-strings', async () => {
160
+ await it('Byte length differs on buffers', async () => {
161
+ expect(
162
+ Buffer.byteLength(Buffer.alloc(0))
163
+ ).toBe(
164
+ Buffer.alloc(0).byteLength
165
+ )
166
+ });
167
+ });
168
+
169
+ await describe('Two Buffers are concatenated', async () => {
170
+ await it('The buffers should be equal', async () => {
171
+ const data1 = [1, 2, 3];
172
+ const data2 = [4, 5, 6];
173
+
174
+ const buffer1 = Buffer.from(data1);
175
+ const buffer2 = Buffer.from(data2);
176
+
177
+ const resultBuffer = Buffer.concat([buffer1, buffer2]);
178
+ const expectedBuffer = Buffer.from([...data1, ...data2]);
179
+ expect(resultBuffer).toEqualArray(expectedBuffer);
180
+ });
181
+ });
182
+
183
+ // TODO: ALso port the tests below
184
+
185
+ // Deno.test({
186
+ // name: "A single buffer concatenates and return the same buffer",
187
+ // fn() {
188
+ // const buffer1 = Buffer.alloc(1);
189
+ // const resultBuffer = Buffer.concat([buffer1]);
190
+ // assertEquals(resultBuffer.length, 1, "Buffer length should be 1");
191
+ // },
192
+ // });
193
+
194
+ // Deno.test({
195
+ // name: "No buffers concat returns an empty buffer",
196
+ // fn() {
197
+ // const resultBuffer = Buffer.concat([]);
198
+ // assertEquals(resultBuffer.length, 0, "Buffer length should be 0");
199
+ // },
200
+ // });
201
+
202
+ // Deno.test({
203
+ // name: "Buffer concat respects totalLength parameter",
204
+ // fn() {
205
+ // const maxLength1 = 10;
206
+ // const buffer1 = Buffer.alloc(2);
207
+ // const buffer2 = Buffer.alloc(2);
208
+ // assertEquals(
209
+ // Buffer.concat([buffer1, buffer2], maxLength1).length,
210
+ // maxLength1,
211
+ // );
212
+
213
+ // const maxLength2 = 3;
214
+ // const buffer3 = Buffer.alloc(2);
215
+ // const buffer4 = Buffer.alloc(2);
216
+ // assertEquals(
217
+ // Buffer.concat([buffer3, buffer4], maxLength2).length,
218
+ // maxLength2,
219
+ // );
220
+ // },
221
+ // });
222
+
223
+ // Deno.test({
224
+ // name: "Buffer 8 bit unsigned integers",
225
+ // fn() {
226
+ // const buffer = Buffer.from([0xff, 0x2a, 0x2a, 0x2a]);
227
+ // assertEquals(buffer.readUInt8(0), 255);
228
+ // assertEquals(buffer.readUInt8(1), 42);
229
+ // assertEquals(buffer.readUInt8(2), 42);
230
+ // assertEquals(buffer.readUInt8(3), 42);
231
+ // },
232
+ // });
233
+
234
+ // Deno.test({
235
+ // name: "Buffer 16 bit unsigned integers",
236
+ // fn() {
237
+ // const buffer = Buffer.from([0x00, 0x2a, 0x42, 0x3f]);
238
+ // assertEquals(buffer.readUInt16BE(0), 0x2a);
239
+ // assertEquals(buffer.readUInt16BE(1), 0x2a42);
240
+ // assertEquals(buffer.readUInt16BE(2), 0x423f);
241
+ // assertEquals(buffer.readUInt16LE(0), 0x2a00);
242
+ // assertEquals(buffer.readUInt16LE(1), 0x422a);
243
+ // assertEquals(buffer.readUInt16LE(2), 0x3f42);
244
+
245
+ // buffer[0] = 0xfe;
246
+ // buffer[1] = 0xfe;
247
+ // assertEquals(buffer.readUInt16BE(0), 0xfefe);
248
+ // assertEquals(buffer.readUInt16LE(0), 0xfefe);
249
+ // },
250
+ // });
251
+
252
+ // Deno.test({
253
+ // name: "Buffer 32 bit unsigned integers",
254
+ // fn() {
255
+ // const buffer = Buffer.from([0x32, 0x65, 0x42, 0x56, 0x23, 0xff]);
256
+ // assertEquals(buffer.readUInt32BE(0), 0x32654256);
257
+ // assertEquals(buffer.readUInt32BE(1), 0x65425623);
258
+ // assertEquals(buffer.readUInt32BE(2), 0x425623ff);
259
+ // assertEquals(buffer.readUInt32LE(0), 0x56426532);
260
+ // assertEquals(buffer.readUInt32LE(1), 0x23564265);
261
+ // assertEquals(buffer.readUInt32LE(2), 0xff235642);
262
+ // },
263
+ // });
264
+
265
+ // Deno.test({
266
+ // name: "Buffer readUIntBE",
267
+ // fn() {
268
+ // const buffer = Buffer.from([
269
+ // 0x01,
270
+ // 0x02,
271
+ // 0x03,
272
+ // 0x04,
273
+ // 0x05,
274
+ // 0x06,
275
+ // 0x07,
276
+ // 0x08,
277
+ // ]);
278
+ // assertEquals(buffer.readUIntBE(0, 1), 0x01);
279
+ // assertEquals(buffer.readUIntBE(0, 2), 0x0102);
280
+ // assertEquals(buffer.readUIntBE(0, 4), 0x01020304);
281
+ // },
282
+ // });
283
+
284
+ // Deno.test({
285
+ // name: "Buffer readUIntLE",
286
+ // fn() {
287
+ // const buffer = Buffer.from([
288
+ // 0x01,
289
+ // 0x02,
290
+ // 0x03,
291
+ // 0x04,
292
+ // 0x05,
293
+ // 0x06,
294
+ // 0x07,
295
+ // 0x08,
296
+ // ]);
297
+ // assertEquals(buffer.readUIntLE(0, 1), 0x01);
298
+ // assertEquals(buffer.readUIntLE(0, 2), 0x0201);
299
+ // assertEquals(buffer.readUIntLE(0, 4), 0x04030201);
300
+ // },
301
+ // });
302
+
303
+ // Deno.test({
304
+ // name: "Buffer copy works as expected",
305
+ // fn() {
306
+ // const data1 = new Uint8Array([1, 2, 3]);
307
+ // const data2 = new Uint8Array([4, 5, 6]);
308
+
309
+ // const buffer1 = Buffer.from(data1);
310
+ // const buffer2 = Buffer.from(data2);
311
+
312
+ // //Mutates data_1
313
+ // data1.set(data2);
314
+ // //Mutates buffer_1
315
+ // buffer2.copy(buffer1);
316
+
317
+ // assertEquals(
318
+ // Buffer.from(data1),
319
+ // buffer1,
320
+ // );
321
+ // },
322
+ // });
323
+
324
+ // Deno.test({
325
+ // name: "Buffer copy respects the starting point for copy",
326
+ // fn() {
327
+ // const buffer1 = Buffer.from([1, 2, 3]);
328
+ // const buffer2 = Buffer.alloc(8);
329
+
330
+ // buffer1.copy(buffer2, 5);
331
+
332
+ // const expected = Buffer.from([0, 0, 0, 0, 0, 1, 2, 3]);
333
+
334
+ // assertEquals(
335
+ // buffer2,
336
+ // expected,
337
+ // );
338
+ // },
339
+ // });
340
+
341
+ // Deno.test({
342
+ // name: "Buffer copy doesn't throw on offset but copies until offset reached",
343
+ // fn() {
344
+ // const buffer1 = Buffer.from([1, 2, 3]);
345
+ // const buffer2 = Buffer.alloc(8);
346
+
347
+ // const writtenBytes1 = buffer1.copy(buffer2, 6);
348
+
349
+ // assertEquals(
350
+ // writtenBytes1,
351
+ // 2,
352
+ // );
353
+
354
+ // assertEquals(
355
+ // buffer2,
356
+ // Buffer.from([0, 0, 0, 0, 0, 0, 1, 2]),
357
+ // );
358
+
359
+ // const buffer3 = Buffer.from([1, 2, 3]);
360
+ // const buffer4 = Buffer.alloc(8);
361
+
362
+ // const writtenBytes2 = buffer3.copy(buffer4, 8);
363
+
364
+ // assertEquals(
365
+ // writtenBytes2,
366
+ // 0,
367
+ // );
368
+
369
+ // assertEquals(
370
+ // buffer4,
371
+ // Buffer.from([0, 0, 0, 0, 0, 0, 0, 0]),
372
+ // );
373
+ // },
374
+ // });
375
+
376
+ // Deno.test({
377
+ // name: "Buffer from string creates a Buffer",
378
+ // fn() {
379
+ // const buffer: Buffer = Buffer.from("test");
380
+ // assertEquals(buffer.length, 4, "Buffer length should be 4");
381
+ // assertEquals(
382
+ // buffer.toString(),
383
+ // "test",
384
+ // "Buffer to string should recover the string",
385
+ // );
386
+ // },
387
+ // });
388
+
389
+ // Deno.test({
390
+ // name: "Buffer from string hex",
391
+ // fn() {
392
+ // for (const encoding of ["hex", "HEX"]) {
393
+ // const buffer: Buffer = Buffer.from(
394
+ // "7468697320697320612074c3a97374",
395
+ // encoding,
396
+ // );
397
+ // assertEquals(buffer.length, 15, "Buffer length should be 15");
398
+ // assertEquals(
399
+ // buffer.toString(),
400
+ // "this is a tést",
401
+ // "Buffer to string should recover the string",
402
+ // );
403
+ // }
404
+ // },
405
+ // });
406
+
407
+ // Deno.test({
408
+ // name: "Buffer from string base64",
409
+ // fn() {
410
+ // for (const encoding of ["base64", "BASE64"]) {
411
+ // const buffer: Buffer = Buffer.from("dGhpcyBpcyBhIHTDqXN0", encoding);
412
+ // assertEquals(buffer.length, 15, "Buffer length should be 15");
413
+ // assertEquals(
414
+ // buffer.toString(),
415
+ // "this is a tést",
416
+ // "Buffer to string should recover the string",
417
+ // );
418
+ // }
419
+ // },
420
+ // });
421
+
422
+ // Deno.test({
423
+ // name: "Buffer to string base64",
424
+ // fn() {
425
+ // for (const encoding of ["base64", "BASE64"]) {
426
+ // const buffer: Buffer = Buffer.from("deno land");
427
+ // assertEquals(
428
+ // buffer.toString(encoding),
429
+ // "ZGVubyBsYW5k",
430
+ // "Buffer to string should recover the string in base64",
431
+ // );
432
+ // }
433
+ // const b64 = "dGhpcyBpcyBhIHTDqXN0";
434
+ // assertEquals(Buffer.from(b64, "base64").toString("base64"), b64);
435
+ // },
436
+ // });
437
+
438
+ // Deno.test({
439
+ // name: "Buffer to string hex",
440
+ // fn() {
441
+ // for (const encoding of ["hex", "HEX"]) {
442
+ // const buffer: Buffer = Buffer.from("deno land");
443
+ // assertEquals(
444
+ // buffer.toString(encoding),
445
+ // "64656e6f206c616e64",
446
+ // "Buffer to string should recover the string",
447
+ // );
448
+ // }
449
+ // const hex = "64656e6f206c616e64";
450
+ // assertEquals(Buffer.from(hex, "hex").toString("hex"), hex);
451
+ // },
452
+ // });
453
+
454
+ // Deno.test({
455
+ // name: "Buffer from string invalid encoding",
456
+ // fn() {
457
+ // const defaultToUtf8Encodings = [null, 5, {}, true, false, ""];
458
+ // const invalidEncodings = ["deno", "base645"];
459
+
460
+ // for (const encoding of defaultToUtf8Encodings) {
461
+ // assertEquals(Buffer.from("yes", encoding).toString(), "yes");
462
+ // }
463
+
464
+ // for (const encoding of invalidEncodings) {
465
+ // assertThrows(
466
+ // () => {
467
+ // Buffer.from("yes", encoding);
468
+ // },
469
+ // TypeError,
470
+ // `Unknown encoding: ${encoding}`,
471
+ // );
472
+ // }
473
+ // },
474
+ // });
475
+
476
+ // Deno.test({
477
+ // name: "Buffer from another buffer creates a Buffer",
478
+ // fn() {
479
+ // const buffer: Buffer = Buffer.from(Buffer.from("test"));
480
+ // assertEquals(buffer.length, 4, "Buffer length should be 4");
481
+ // assertEquals(
482
+ // buffer.toString(),
483
+ // "test",
484
+ // "Buffer to string should recover the string",
485
+ // );
486
+ // },
487
+ // });
488
+
489
+ // Deno.test({
490
+ // name: "isBuffer returns true if the object is a buffer",
491
+ // fn() {
492
+ // assertEquals(Buffer.isBuffer(Buffer.from("test")), true);
493
+ // },
494
+ // });
495
+
496
+ // Deno.test({
497
+ // name: "isBuffer returns false if the object is not a buffer",
498
+ // fn() {
499
+ // assertEquals(Buffer.isBuffer({ test: 3 }), false);
500
+ // assertEquals(Buffer.isBuffer(new Uint8Array()), false);
501
+ // },
502
+ // });
503
+
504
+ // Deno.test({
505
+ // name: "Buffer toJSON",
506
+ // fn() {
507
+ // assertEquals(
508
+ // JSON.stringify(Buffer.from("deno")),
509
+ // '{"type":"Buffer","data":[100,101,110,111]}',
510
+ // );
511
+ // },
512
+ // });
513
+
514
+ // Deno.test({
515
+ // name: "buf.slice does not create a copy",
516
+ // fn() {
517
+ // const buf = Buffer.from("ceno");
518
+ // // This method is not compatible with the Uint8Array.prototype.slice()
519
+ // const slice = buf.slice();
520
+ // slice[0]++;
521
+ // assertEquals(slice.toString(), "deno");
522
+ // },
523
+ // });
524
+
525
+ // Deno.test({
526
+ // name: "isEncoding returns true for valid encodings",
527
+ // fn() {
528
+ // [
529
+ // "hex",
530
+ // "HEX",
531
+ // "HeX",
532
+ // "utf8",
533
+ // "utf-8",
534
+ // "ascii",
535
+ // "latin1",
536
+ // "binary",
537
+ // "base64",
538
+ // "BASE64",
539
+ // "BASe64",
540
+ // "ucs2",
541
+ // "ucs-2",
542
+ // "utf16le",
543
+ // "utf-16le",
544
+ // ].forEach((enc) => {
545
+ // assertEquals(Buffer.isEncoding(enc), true);
546
+ // });
547
+ // },
548
+ // });
549
+
550
+ // Deno.test({
551
+ // name: "isEncoding returns false for invalid encodings",
552
+ // fn() {
553
+ // [
554
+ // "utf9",
555
+ // "utf-7",
556
+ // "Unicode-FTW",
557
+ // "new gnu gun",
558
+ // false,
559
+ // NaN,
560
+ // {},
561
+ // Infinity,
562
+ // [],
563
+ // 1,
564
+ // 0,
565
+ // -1,
566
+ // ].forEach((enc) => {
567
+ // // @ts-expect-error This deliberately ignores the type constraint
568
+ // assertEquals(Buffer.isEncoding(enc), false);
569
+ // });
570
+ // },
571
+ // });
572
+
573
+ // Deno.test({
574
+ // name:
575
+ // "utf8Write handle missing optional length argument (https://github.com/denoland/deno_std/issues/2046)",
576
+ // fn() {
577
+ // const buf = Buffer.alloc(8);
578
+ // // @ts-expect-error Buffer.prototype.utf8Write is an undocumented API
579
+ // assertEquals(buf.utf8Write("abc", 0), 3);
580
+ // assertEquals([...buf], [0x61, 0x62, 0x63, 0, 0, 0, 0, 0]);
581
+ // },
582
+ // });
583
+ }
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from '@gjsify/deno_std/node/buffer';
2
+ import buffer from '@gjsify/deno_std/node/buffer';
3
+ export default buffer;