@gjsify/buffer 0.4.0 → 0.4.3
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/lib/esm/blob.js +1 -1
- package/lib/types/blob.d.ts +1 -12
- package/lib/types/index.d.ts +0 -11
- package/package.json +48 -45
- package/src/blob.ts +0 -77
- package/src/buffer.ts +0 -786
- package/src/index.spec.ts +0 -1139
- package/src/index.ts +0 -38
- package/src/register.ts +0 -9
- package/src/test.mts +0 -7
- package/tsconfig.json +0 -29
- package/tsconfig.tsbuildinfo +0 -1
package/lib/esm/blob.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";const e=new TextEncoder;var t=class BlobPolyfill{_parts;size;type;constructor(t,n){this._parts=t||[],this.type=n?.type||``,this.size=this._parts.reduce((t,n)=>typeof n==`string`?t+e.encode(n).byteLength:n instanceof ArrayBuffer||ArrayBuffer.isView(n)?t+n.byteLength:n&&typeof n.size==`number`?t+n.size:t,0)}async bytes(){let e=await this.arrayBuffer();return new Uint8Array(e)}async text(){return new TextDecoder().decode(await this.arrayBuffer())}async arrayBuffer(){let t=[];for(let n of this._parts)if(typeof n==`string`)t.push(e.encode(n));else if(n instanceof ArrayBuffer)t.push(new Uint8Array(n));else if(ArrayBuffer.isView(n))t.push(new Uint8Array(n.buffer,n.byteOffset,n.byteLength));else if(n&&typeof n.arrayBuffer==`function`){let e=await n.arrayBuffer();t.push(new Uint8Array(e))}let n=t.reduce((e,t)=>e+t.byteLength,0),r=new Uint8Array(n),i=0;for(let e of t)r.set(e,i),i+=e.byteLength;return r.buffer}slice(e,t,n){return new BlobPolyfill([],{type:n})}stream(){
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";const e=new TextEncoder;var t=class BlobPolyfill{_parts;size;type;constructor(t,n){this._parts=t||[],this.type=n?.type||``,this.size=this._parts.reduce((t,n)=>typeof n==`string`?t+e.encode(n).byteLength:n instanceof ArrayBuffer||ArrayBuffer.isView(n)?t+n.byteLength:n&&typeof n.size==`number`?t+n.size:t,0)}async bytes(){let e=await this.arrayBuffer();return new Uint8Array(e)}async text(){return new TextDecoder().decode(await this.arrayBuffer())}async arrayBuffer(){let t=[];for(let n of this._parts)if(typeof n==`string`)t.push(e.encode(n));else if(n instanceof ArrayBuffer)t.push(new Uint8Array(n));else if(ArrayBuffer.isView(n))t.push(new Uint8Array(n.buffer,n.byteOffset,n.byteLength));else if(n&&typeof n.arrayBuffer==`function`){let e=await n.arrayBuffer();t.push(new Uint8Array(e))}let n=t.reduce((e,t)=>e+t.byteLength,0),r=new Uint8Array(n),i=0;for(let e of t)r.set(e,i),i+=e.byteLength;return r.buffer}slice(e,t,n){return new BlobPolyfill([],{type:n})}stream(){let e=this;return new ReadableStream({async pull(t){let n=await e.arrayBuffer();t.enqueue(new Uint8Array(n)),t.close()}})}},FilePolyfill=class extends t{name;lastModified;webkitRelativePath=``;constructor(e,t,n){super(e,n),this.name=t,this.lastModified=n?.lastModified??Date.now()}};const n=globalThis.Blob??t,r=globalThis.File??FilePolyfill;export{n as Blob,r as File};
|
package/lib/types/blob.d.ts
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
declare
|
|
2
|
-
_parts: BlobPart[];
|
|
3
|
-
readonly size: number;
|
|
4
|
-
readonly type: string;
|
|
5
|
-
constructor(parts?: BlobPart[], options?: BlobPropertyBag);
|
|
6
|
-
bytes(): Promise<Uint8Array<ArrayBuffer>>;
|
|
7
|
-
text(): Promise<string>;
|
|
8
|
-
arrayBuffer(): Promise<ArrayBuffer>;
|
|
9
|
-
slice(start?: number, end?: number, type?: string): Blob;
|
|
10
|
-
stream(): ReadableStream;
|
|
11
|
-
}
|
|
12
|
-
declare const Blob: typeof BlobPolyfill | {
|
|
1
|
+
declare const Blob: {
|
|
13
2
|
new (blobParts?: BlobPart[], options?: BlobPropertyBag): Blob;
|
|
14
3
|
prototype: Blob;
|
|
15
4
|
};
|
package/lib/types/index.d.ts
CHANGED
|
@@ -9,17 +9,6 @@ declare const _default: {
|
|
|
9
9
|
Buffer: typeof Buffer;
|
|
10
10
|
SlowBuffer: typeof SlowBuffer;
|
|
11
11
|
Blob: {
|
|
12
|
-
new (parts?: BlobPart[], options?: BlobPropertyBag): {
|
|
13
|
-
_parts: BlobPart[];
|
|
14
|
-
readonly size: number;
|
|
15
|
-
readonly type: string;
|
|
16
|
-
bytes(): Promise<Uint8Array<ArrayBuffer>>;
|
|
17
|
-
text(): Promise<string>;
|
|
18
|
-
arrayBuffer(): Promise<ArrayBuffer>;
|
|
19
|
-
slice(start?: number, end?: number, type?: string): Blob;
|
|
20
|
-
stream(): ReadableStream;
|
|
21
|
-
};
|
|
22
|
-
} | {
|
|
23
12
|
new (blobParts?: BlobPart[], options?: BlobPropertyBag): Blob;
|
|
24
13
|
prototype: Blob;
|
|
25
14
|
};
|
package/package.json
CHANGED
|
@@ -1,48 +1,51 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
"name": "@gjsify/buffer",
|
|
3
|
+
"version": "0.4.3",
|
|
4
|
+
"description": "Node.js buffer module for Gjs",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"module": "lib/esm/index.js",
|
|
7
|
+
"types": "lib/types/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./lib/types/index.d.ts",
|
|
11
|
+
"default": "./lib/esm/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./register": {
|
|
14
|
+
"types": "./lib/types/register.d.ts",
|
|
15
|
+
"default": "./lib/esm/register.js"
|
|
16
|
+
}
|
|
12
17
|
},
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
"files": [
|
|
19
|
+
"lib"
|
|
20
|
+
],
|
|
21
|
+
"sideEffects": [
|
|
22
|
+
"./lib/esm/register.js"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"clear": "rm -rf lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo test.gjs.mjs test.node.mjs || exit 0",
|
|
26
|
+
"check": "tsc --noEmit",
|
|
27
|
+
"build": "gjsify run build:gjsify && gjsify run build:types",
|
|
28
|
+
"build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
|
|
29
|
+
"build:types": "tsc",
|
|
30
|
+
"build:test": "gjsify run build:test:gjs && gjsify run build:test:node",
|
|
31
|
+
"build:test:gjs": "gjsify build src/test.mts --app gjs --outfile test.gjs.mjs",
|
|
32
|
+
"build:test:node": "gjsify build src/test.mts --app node --outfile test.node.mjs",
|
|
33
|
+
"test": "gjsify run build:gjsify && gjsify run build:test && gjsify run test:node && gjsify run test:gjs",
|
|
34
|
+
"test:gjs": "gjsify run test.gjs.mjs",
|
|
35
|
+
"test:node": "node test.node.mjs"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"gjs",
|
|
39
|
+
"node",
|
|
40
|
+
"buffer"
|
|
41
|
+
],
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@gjsify/cli": "workspace:^",
|
|
44
|
+
"@gjsify/unit": "workspace:^",
|
|
45
|
+
"@types/node": "^25.6.2",
|
|
46
|
+
"typescript": "^6.0.3"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@gjsify/utils": "workspace:^"
|
|
16
50
|
}
|
|
17
|
-
|
|
18
|
-
"sideEffects": [
|
|
19
|
-
"./lib/esm/register.js"
|
|
20
|
-
],
|
|
21
|
-
"scripts": {
|
|
22
|
-
"clear": "rm -rf lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo test.gjs.mjs test.node.mjs || exit 0",
|
|
23
|
-
"check": "tsc --noEmit",
|
|
24
|
-
"build": "yarn build:gjsify && yarn build:types",
|
|
25
|
-
"build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
|
|
26
|
-
"build:types": "tsc",
|
|
27
|
-
"build:test": "yarn build:test:gjs && yarn build:test:node",
|
|
28
|
-
"build:test:gjs": "gjsify build src/test.mts --app gjs --outfile test.gjs.mjs",
|
|
29
|
-
"build:test:node": "gjsify build src/test.mts --app node --outfile test.node.mjs",
|
|
30
|
-
"test": "yarn build:gjsify && yarn build:test && yarn test:node && yarn test:gjs",
|
|
31
|
-
"test:gjs": "gjsify run test.gjs.mjs",
|
|
32
|
-
"test:node": "node test.node.mjs"
|
|
33
|
-
},
|
|
34
|
-
"keywords": [
|
|
35
|
-
"gjs",
|
|
36
|
-
"node",
|
|
37
|
-
"buffer"
|
|
38
|
-
],
|
|
39
|
-
"devDependencies": {
|
|
40
|
-
"@gjsify/cli": "^0.4.0",
|
|
41
|
-
"@gjsify/unit": "^0.4.0",
|
|
42
|
-
"@types/node": "^25.6.2",
|
|
43
|
-
"typescript": "^6.0.3"
|
|
44
|
-
},
|
|
45
|
-
"dependencies": {
|
|
46
|
-
"@gjsify/utils": "^0.4.0"
|
|
47
|
-
}
|
|
48
|
-
}
|
|
51
|
+
}
|
package/src/blob.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
// WHATWG Blob/File polyfill for GJS
|
|
2
|
-
// Reference: Node.js lib/buffer.js (Blob), refs/deno/ext/web/09_file.js
|
|
3
|
-
// Node.js exports Blob from 'node:buffer' since v18.
|
|
4
|
-
// On GJS, globalThis.Blob is not available — this provides a minimal polyfill.
|
|
5
|
-
|
|
6
|
-
const _encoder = new TextEncoder();
|
|
7
|
-
|
|
8
|
-
class BlobPolyfill implements Blob {
|
|
9
|
-
_parts: BlobPart[];
|
|
10
|
-
readonly size: number;
|
|
11
|
-
readonly type: string;
|
|
12
|
-
|
|
13
|
-
constructor(parts?: BlobPart[], options?: BlobPropertyBag) {
|
|
14
|
-
this._parts = parts || [];
|
|
15
|
-
this.type = options?.type || '';
|
|
16
|
-
this.size = this._parts.reduce((acc: number, part: BlobPart) => {
|
|
17
|
-
if (typeof part === 'string') return acc + _encoder.encode(part).byteLength;
|
|
18
|
-
if (part instanceof ArrayBuffer) return acc + part.byteLength;
|
|
19
|
-
if (ArrayBuffer.isView(part)) return acc + part.byteLength;
|
|
20
|
-
if (part && typeof (part as Blob).size === 'number') return acc + (part as Blob).size;
|
|
21
|
-
return acc;
|
|
22
|
-
}, 0);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async bytes(): Promise<Uint8Array<ArrayBuffer>> {
|
|
26
|
-
const ab = await this.arrayBuffer();
|
|
27
|
-
return new Uint8Array(ab);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async text(): Promise<string> {
|
|
31
|
-
return new TextDecoder().decode(await this.arrayBuffer());
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async arrayBuffer(): Promise<ArrayBuffer> {
|
|
35
|
-
const chunks: Uint8Array[] = [];
|
|
36
|
-
for (const part of this._parts) {
|
|
37
|
-
if (typeof part === 'string') chunks.push(_encoder.encode(part));
|
|
38
|
-
else if (part instanceof ArrayBuffer) chunks.push(new Uint8Array(part));
|
|
39
|
-
else if (ArrayBuffer.isView(part)) chunks.push(new Uint8Array(part.buffer as ArrayBuffer, part.byteOffset, part.byteLength));
|
|
40
|
-
else if (part && typeof (part as Blob).arrayBuffer === 'function') {
|
|
41
|
-
const ab = await (part as Blob).arrayBuffer();
|
|
42
|
-
chunks.push(new Uint8Array(ab));
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
const total = chunks.reduce((a, c) => a + c.byteLength, 0);
|
|
46
|
-
const result = new Uint8Array(total);
|
|
47
|
-
let offset = 0;
|
|
48
|
-
for (const c of chunks) { result.set(c, offset); offset += c.byteLength; }
|
|
49
|
-
return result.buffer as ArrayBuffer;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
slice(start?: number, end?: number, type?: string): Blob {
|
|
53
|
-
return new BlobPolyfill([], { type }) as unknown as Blob;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
stream(): ReadableStream {
|
|
57
|
-
throw new Error('Blob.stream() not implemented');
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
class FilePolyfill extends BlobPolyfill {
|
|
62
|
-
readonly name: string;
|
|
63
|
-
readonly lastModified: number;
|
|
64
|
-
readonly webkitRelativePath: string = '';
|
|
65
|
-
|
|
66
|
-
constructor(parts: BlobPart[], name: string, options?: FilePropertyBag) {
|
|
67
|
-
super(parts, options);
|
|
68
|
-
this.name = name;
|
|
69
|
-
this.lastModified = options?.lastModified ?? Date.now();
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Use native if available, polyfill otherwise
|
|
74
|
-
const Blob = globalThis.Blob ?? BlobPolyfill;
|
|
75
|
-
const File = (globalThis as any).File ?? FilePolyfill;
|
|
76
|
-
|
|
77
|
-
export { Blob, File };
|