@gjsify/buffer 0.4.36 → 0.4.37

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 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(){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};
1
+ import"./_virtual/_rolldown/runtime.js";let e;const _encoder=()=>e??=new TextEncoder;var t=class BlobPolyfill{_parts;size;type;constructor(e,t){this._parts=e||[],this.type=t?.type||``,this.size=this._parts.reduce((e,t)=>typeof t==`string`?e+_encoder().encode(t).byteLength:t instanceof ArrayBuffer||ArrayBuffer.isView(t)?e+t.byteLength:t&&typeof t.size==`number`?e+t.size:e,0)}async bytes(){let e=await this.arrayBuffer();return new Uint8Array(e)}async text(){return new TextDecoder().decode(await this.arrayBuffer())}async arrayBuffer(){let e=[];for(let t of this._parts)if(typeof t==`string`)e.push(_encoder().encode(t));else if(t instanceof ArrayBuffer)e.push(new Uint8Array(t));else if(ArrayBuffer.isView(t))e.push(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));else if(t&&typeof t.arrayBuffer==`function`){let n=await t.arrayBuffer();e.push(new Uint8Array(n))}let t=e.reduce((e,t)=>e+t.byteLength,0),n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.byteLength;return n.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};
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{base64Decode as e,btoaPolyfill as t}from"./base64.js";const n=new TextEncoder,r=new TextDecoder;function encodeString(t,r){switch(r){case`utf8`:return n.encode(t);case`ascii`:{let e=new Uint8Array(t.length);for(let n=0;n<t.length;n++)e[n]=t.charCodeAt(n)&127;return e}case`latin1`:{let e=new Uint8Array(t.length);for(let n=0;n<t.length;n++)e[n]=t.charCodeAt(n)&255;return e}case`base64`:return e(t.replace(/-/g,`+`).replace(/_/g,`/`));case`base64url`:return encodeString(t.replace(/-/g,`+`).replace(/_/g,`/`),`base64`);case`hex`:{let e=t.length>>>1,n=new Uint8Array(e);for(let r=0;r<e;r++){let e=parseInt(t[r*2],16),i=parseInt(t[r*2+1],16);if(Number.isNaN(e)||Number.isNaN(i))break;n[r]=e<<4|i}return n}case`utf16le`:{let e=new Uint8Array(t.length*2);for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e[n*2]=r&255,e[n*2+1]=r>>8&255}return e}default:return n.encode(t)}}function decodeString(e,n,i,a){let o=i!==void 0||a!==void 0?e.subarray(i??0,a??e.length):e;switch(n){case`utf8`:return r.decode(o);case`ascii`:{let e=``;for(let t=0;t<o.length;t++)e+=String.fromCharCode(o[t]&127);return e}case`latin1`:{let e=``;for(let t=0;t<o.length;t++)e+=String.fromCharCode(o[t]);return e}case`base64`:{let e=``;for(let t=0;t<o.length;t++)e+=String.fromCharCode(o[t]);return t(e)}case`base64url`:return decodeString(o,`base64`).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``);case`hex`:{let e=``;for(let t=0;t<o.length;t++)e+=o[t].toString(16).padStart(2,`0`);return e}case`utf16le`:{let e=``;for(let t=0;t+1<o.length;t+=2)e+=String.fromCharCode(o[t]|o[t+1]<<8);return e}default:return r.decode(o)}}function checkOffset(e,t,n){if(e+t>n)throw RangeError(`Attempt to access memory outside buffer bounds`)}export{checkOffset,decodeString,encodeString};
1
+ import"./_virtual/_rolldown/runtime.js";import{base64Decode as e,btoaPolyfill as t}from"./base64.js";let n,r;const textEncoder=()=>n??=new TextEncoder,textDecoder=()=>r??=new TextDecoder;function encodeString(t,n){switch(n){case`utf8`:return textEncoder().encode(t);case`ascii`:{let e=new Uint8Array(t.length);for(let n=0;n<t.length;n++)e[n]=t.charCodeAt(n)&127;return e}case`latin1`:{let e=new Uint8Array(t.length);for(let n=0;n<t.length;n++)e[n]=t.charCodeAt(n)&255;return e}case`base64`:return e(t.replace(/-/g,`+`).replace(/_/g,`/`));case`base64url`:return encodeString(t.replace(/-/g,`+`).replace(/_/g,`/`),`base64`);case`hex`:{let e=t.length>>>1,n=new Uint8Array(e);for(let r=0;r<e;r++){let e=parseInt(t[r*2],16),i=parseInt(t[r*2+1],16);if(Number.isNaN(e)||Number.isNaN(i))break;n[r]=e<<4|i}return n}case`utf16le`:{let e=new Uint8Array(t.length*2);for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e[n*2]=r&255,e[n*2+1]=r>>8&255}return e}default:return textEncoder().encode(t)}}function decodeString(e,n,r,i){let a=r!==void 0||i!==void 0?e.subarray(r??0,i??e.length):e;switch(n){case`utf8`:return textDecoder().decode(a);case`ascii`:{let e=``;for(let t=0;t<a.length;t++)e+=String.fromCharCode(a[t]&127);return e}case`latin1`:{let e=``;for(let t=0;t<a.length;t++)e+=String.fromCharCode(a[t]);return e}case`base64`:{let e=``;for(let t=0;t<a.length;t++)e+=String.fromCharCode(a[t]);return t(e)}case`base64url`:return decodeString(a,`base64`).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``);case`hex`:{let e=``;for(let t=0;t<a.length;t++)e+=a[t].toString(16).padStart(2,`0`);return e}case`utf16le`:{let e=``;for(let t=0;t+1<a.length;t+=2)e+=String.fromCharCode(a[t]|a[t+1]<<8);return e}default:return textDecoder().decode(a)}}function checkOffset(e,t,n){if(e+t>n)throw RangeError(`Attempt to access memory outside buffer bounds`)}export{checkOffset,decodeString,encodeString};
@@ -0,0 +1,2 @@
1
+ declare const _default: () => Promise<void>;
2
+ export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/buffer",
3
- "version": "0.4.36",
3
+ "version": "0.4.37",
4
4
  "description": "Node.js buffer module for Gjs",
5
5
  "type": "module",
6
6
  "module": "lib/esm/index.js",
@@ -44,19 +44,20 @@
44
44
  "buffer"
45
45
  ],
46
46
  "devDependencies": {
47
- "@gjsify/cli": "^0.4.36",
48
- "@gjsify/unit": "^0.4.36",
47
+ "@gjsify/cli": "^0.4.37",
48
+ "@gjsify/unit": "^0.4.37",
49
49
  "@types/node": "^25.9.1",
50
50
  "typescript": "^5.9.3"
51
51
  },
52
52
  "dependencies": {
53
- "@gjsify/utils": "^0.4.36"
53
+ "@gjsify/utils": "^0.4.37"
54
54
  },
55
55
  "gjsify": {
56
56
  "runtimes": {
57
57
  "gjs": "polyfill",
58
58
  "node": "native",
59
- "browser": "polyfill"
59
+ "browser": "polyfill",
60
+ "nativescript": "polyfill"
60
61
  }
61
62
  },
62
63
  "license": "MIT",