balloc 1.3.0 → 1.4.0
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/CHANGELOG.md +18 -0
- package/README.MD +37 -7
- package/README.ar.md +31 -1
- package/README.en.md +37 -7
- package/README.es.md +31 -1
- package/README.jp.md +31 -1
- package/README.pt.md +36 -7
- package/README.zh.md +31 -1
- package/docs/API /342/200/224 balloc.ar.md" +56 -0
- package/docs/API /342/200/224 balloc.en.md" +55 -0
- package/docs/API /342/200/224 balloc.es.md" +56 -0
- package/docs/API /342/200/224 balloc.jp.md" +56 -0
- package/docs/API /342/200/224 balloc.pt.md" +56 -0
- package/docs/API /342/200/224 balloc.zh.md" +56 -0
- package/package.json +1 -1
- package/src/ar/balloc.cjs +63 -35
- package/src/ar/balloc.js +1 -1
- package/src/ar/balloc.mjs +78 -39
- package/src/en/balloc.cjs +65 -35
- package/src/en/balloc.js +1 -1
- package/src/en/balloc.mjs +80 -39
- package/src/es/balloc.cjs +65 -35
- package/src/es/balloc.js +1 -1
- package/src/es/balloc.mjs +80 -39
- package/src/jp/balloc.cjs +65 -35
- package/src/jp/balloc.js +1 -1
- package/src/jp/balloc.mjs +80 -39
- package/src/pt/balloc.cjs +67 -35
- package/src/pt/balloc.js +1 -1
- package/src/pt/balloc.mjs +86 -38
- package/src/zh/balloc.cjs +63 -35
- package/src/zh/balloc.js +1 -1
- package/src/zh/balloc.mjs +78 -39
- package/types/ar/balloc.d.mts +36 -1
- package/types/en/balloc.d.mts +38 -1
- package/types/es/balloc.d.mts +38 -1
- package/types/jp/balloc.d.mts +38 -1
- package/types/pt/balloc.d.mts +41 -0
- package/types/zh/balloc.d.mts +36 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,24 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.4.0] - 2026-11-23
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Added the `loadData(adapter)` method and the `FormatAdapter` ingestion contract.
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
- Refactored `withView()`.
|
|
15
|
+
- Deprecated `assertNotBorrowed()`.
|
|
16
|
+
|
|
17
|
+
## [1.3.1] - 2026-11-19
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
- Added the `borrowed` field to the internal `Metadata` structure.
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
- `extractMetadata()` now decodes the `borrowed` flag.
|
|
24
|
+
- Refactored `withView()` from a multi-pass to a single-pass borrow algorithm.
|
|
25
|
+
|
|
8
26
|
## [1.3.0] - 2026-11-19
|
|
9
27
|
|
|
10
28
|
### Added
|
package/README.MD
CHANGED
|
@@ -85,28 +85,28 @@ The generation is used by the allocator's *cookie* validation mechanism to detec
|
|
|
85
85
|
In Node.js, install the following NPM package:
|
|
86
86
|
|
|
87
87
|
```bash
|
|
88
|
-
npm install
|
|
88
|
+
npm install balloc
|
|
89
89
|
|
|
90
90
|
```
|
|
91
91
|
|
|
92
92
|
In Bun, install:
|
|
93
93
|
|
|
94
94
|
```bash
|
|
95
|
-
bun add
|
|
95
|
+
bun add balloc
|
|
96
96
|
|
|
97
97
|
```
|
|
98
98
|
|
|
99
99
|
In Deno, install:
|
|
100
100
|
|
|
101
101
|
```bash
|
|
102
|
-
deno add npm:
|
|
102
|
+
deno add npm:balloc
|
|
103
103
|
|
|
104
104
|
```
|
|
105
105
|
|
|
106
106
|
Using Yarn:
|
|
107
107
|
|
|
108
108
|
```bash
|
|
109
|
-
yarn add
|
|
109
|
+
yarn add balloc
|
|
110
110
|
|
|
111
111
|
```
|
|
112
112
|
|
|
@@ -151,7 +151,7 @@ Chinese: [https://cdn.jsdelivr.net/npm/Balloc/src/zh/Balloc.mjs](https://cdn.j
|
|
|
151
151
|
ESM:
|
|
152
152
|
|
|
153
153
|
```js
|
|
154
|
-
import Balloc from "
|
|
154
|
+
import Balloc from "balloc";
|
|
155
155
|
|
|
156
156
|
const memory = new Balloc();
|
|
157
157
|
|
|
@@ -174,7 +174,7 @@ memory.free(handler);
|
|
|
174
174
|
CJS:
|
|
175
175
|
|
|
176
176
|
```js
|
|
177
|
-
const Balloc = require("
|
|
177
|
+
const Balloc = require("balloc").default;
|
|
178
178
|
|
|
179
179
|
const memory = new Balloc();
|
|
180
180
|
|
|
@@ -312,6 +312,7 @@ The complete API documentation is available in the [`./docs`](./docs) directory
|
|
|
312
312
|
The API methods are grouped by affinity into the following categories:
|
|
313
313
|
|
|
314
314
|
* Lifecycle
|
|
315
|
+
* Data ingestion adapters
|
|
315
316
|
* Stack operations
|
|
316
317
|
* Queue operations
|
|
317
318
|
* Array operations
|
|
@@ -322,6 +323,35 @@ The API methods are grouped by affinity into the following categories:
|
|
|
322
323
|
|
|
323
324
|
The following is a summary of these groups:
|
|
324
325
|
|
|
326
|
+
### Data ingestion adapters
|
|
327
|
+
|
|
328
|
+
`loadData(adapter)` delegates synchronous data ingestion to an adapter implementing the `FormatAdapter` contract. The adapter receives the allocator and returns the numeric handler for the primary block it loads.
|
|
329
|
+
|
|
330
|
+
```ts
|
|
331
|
+
interface FormatAdapter {
|
|
332
|
+
load(allocator: Balloc): number;
|
|
333
|
+
}
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
The allocator does not manage adapter transactions. If an adapter allocates multiple blocks and a later operation fails, rollback of those allocations is the adapter's responsibility.
|
|
337
|
+
|
|
338
|
+
Example:
|
|
339
|
+
|
|
340
|
+
```js
|
|
341
|
+
import Balloc from "balloc";
|
|
342
|
+
|
|
343
|
+
const allocator = new Balloc(65535, "8u");
|
|
344
|
+
const handler = allocator.loadData({
|
|
345
|
+
load(allocator) {
|
|
346
|
+
const handler = allocator.alloc(4);
|
|
347
|
+
allocator.put(handler, new Uint8Array([255, 0, 0, 255]));
|
|
348
|
+
return handler;
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
Format-specific adapters can be published independently. For example, `imagedata-adapter` ingests RGBA8 `ImageData` instances.
|
|
354
|
+
|
|
325
355
|
### Lifecycle
|
|
326
356
|
|
|
327
357
|
| API | Description |
|
|
@@ -434,7 +464,7 @@ If you like this project and want to support its development:
|
|
|
434
464
|
|
|
435
465
|
| Pix QR Code | Copy-and-Paste / Random Key |
|
|
436
466
|
| :---: | :--- |
|
|
437
|
-
|  | **Random Key:**<br>`e87d773a-0b97-4410-8fc3-f7ec04cce6a2` |
|
|
467
|
+
|  | **Random Key:**<br>`e87d773a-0b97-4410-8fc3-f7ec04cce6a2` |
|
|
438
468
|
|
|
439
469
|
## License
|
|
440
470
|
|
package/README.ar.md
CHANGED
|
@@ -284,6 +284,7 @@ alloc()
|
|
|
284
284
|
تُصنَّف أساليب API بحسب الوظيفة ضمن المجموعات التالية:
|
|
285
285
|
|
|
286
286
|
* إدارة دورة الحياة
|
|
287
|
+
* محولات إدخال البيانات
|
|
287
288
|
* عمليات المكدس
|
|
288
289
|
* عمليات الطابور
|
|
289
290
|
* عمليات المصفوفات
|
|
@@ -294,6 +295,35 @@ alloc()
|
|
|
294
295
|
|
|
295
296
|
وفيما يلي ملخص هذه المجموعات.
|
|
296
297
|
|
|
298
|
+
### محولات إدخال البيانات
|
|
299
|
+
|
|
300
|
+
تُفوِّض `loadData(adapter)` عملية إدخال البيانات المتزامنة إلى محوّل يطبّق عقد `FormatAdapter`. يتلقى المحوّل كائن المُخصِّص ويعيد المقبض الرقمي للكتلة الأساسية التي حمّلها.
|
|
301
|
+
|
|
302
|
+
```ts
|
|
303
|
+
interface FormatAdapter {
|
|
304
|
+
load(allocator: Balloc): number;
|
|
305
|
+
}
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
لا يدير المُخصِّص المعاملات الخاصة بالمحوّل. إذا خصّص المحوّل عدة كتل وفشلت عملية لاحقة، فإن مسؤولية التراجع عن تلك التخصيصات تقع على عاتق المحوّل.
|
|
309
|
+
|
|
310
|
+
مثال:
|
|
311
|
+
|
|
312
|
+
```js
|
|
313
|
+
import Balloc from "balloc";
|
|
314
|
+
|
|
315
|
+
const allocator = new Balloc(65535, "8u");
|
|
316
|
+
const handler = allocator.loadData({
|
|
317
|
+
load(allocator) {
|
|
318
|
+
const handler = allocator.alloc(4);
|
|
319
|
+
allocator.put(handler, new Uint8Array([255, 0, 0, 255]));
|
|
320
|
+
return handler;
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
يمكن نشر المحوّلات الخاصة بكل تنسيق بشكل مستقل. على سبيل المثال، تستوعب حزمة `imagedata-adapter` كائنات `ImageData` بتنسيق RGBA8.
|
|
326
|
+
|
|
297
327
|
### إدارة دورة الحياة
|
|
298
328
|
|
|
299
329
|
| API | الوصف |
|
|
@@ -402,7 +432,7 @@ alloc()
|
|
|
402
432
|
|
|
403
433
|
| رمز QR لخدمة Pix | مفتاح النسخ واللصق / المفتاح العشوائي |
|
|
404
434
|
| :---: | :--- |
|
|
405
|
-
|  | **المفتاح العشوائي:**<br>`e87d773a-0b97-4410-8fc3-f7ec04cce6a2` |
|
|
435
|
+
|  | **المفتاح العشوائي:**<br>`e87d773a-0b97-4410-8fc3-f7ec04cce6a2` |
|
|
406
436
|
|
|
407
437
|
## الترخيص
|
|
408
438
|
|
package/README.en.md
CHANGED
|
@@ -85,28 +85,28 @@ The generation is used by the allocator's *cookie* validation mechanism to detec
|
|
|
85
85
|
In Node.js, install the following NPM package:
|
|
86
86
|
|
|
87
87
|
```bash
|
|
88
|
-
npm install
|
|
88
|
+
npm install balloc
|
|
89
89
|
|
|
90
90
|
```
|
|
91
91
|
|
|
92
92
|
In Bun, install:
|
|
93
93
|
|
|
94
94
|
```bash
|
|
95
|
-
bun add
|
|
95
|
+
bun add balloc
|
|
96
96
|
|
|
97
97
|
```
|
|
98
98
|
|
|
99
99
|
In Deno, install:
|
|
100
100
|
|
|
101
101
|
```bash
|
|
102
|
-
deno add npm:
|
|
102
|
+
deno add npm:balloc
|
|
103
103
|
|
|
104
104
|
```
|
|
105
105
|
|
|
106
106
|
Using Yarn:
|
|
107
107
|
|
|
108
108
|
```bash
|
|
109
|
-
yarn add
|
|
109
|
+
yarn add balloc
|
|
110
110
|
|
|
111
111
|
```
|
|
112
112
|
|
|
@@ -151,7 +151,7 @@ Chinese: [https://cdn.jsdelivr.net/npm/Balloc/src/zh/Balloc.mjs](https://cdn.j
|
|
|
151
151
|
ESM:
|
|
152
152
|
|
|
153
153
|
```js
|
|
154
|
-
import Balloc from "
|
|
154
|
+
import Balloc from "balloc";
|
|
155
155
|
|
|
156
156
|
const memory = new Balloc();
|
|
157
157
|
|
|
@@ -174,7 +174,7 @@ memory.free(handler);
|
|
|
174
174
|
CJS:
|
|
175
175
|
|
|
176
176
|
```js
|
|
177
|
-
const Balloc = require("
|
|
177
|
+
const Balloc = require("balloc").default;
|
|
178
178
|
|
|
179
179
|
const memory = new Balloc();
|
|
180
180
|
|
|
@@ -311,6 +311,7 @@ The complete API documentation is available in the [`./docs`](./docs) directory
|
|
|
311
311
|
The API methods are grouped by affinity into the following categories:
|
|
312
312
|
|
|
313
313
|
* Lifecycle
|
|
314
|
+
* Data ingestion adapters
|
|
314
315
|
* Stack operations
|
|
315
316
|
* Queue operations
|
|
316
317
|
* Array operations
|
|
@@ -321,6 +322,35 @@ The API methods are grouped by affinity into the following categories:
|
|
|
321
322
|
|
|
322
323
|
The following is a summary of these groups:
|
|
323
324
|
|
|
325
|
+
### Data ingestion adapters
|
|
326
|
+
|
|
327
|
+
`loadData(adapter)` delegates synchronous data ingestion to an adapter implementing the `FormatAdapter` contract. The adapter receives the allocator and returns the numeric handler for the primary block it loads.
|
|
328
|
+
|
|
329
|
+
```ts
|
|
330
|
+
interface FormatAdapter {
|
|
331
|
+
load(allocator: Balloc): number;
|
|
332
|
+
}
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
The allocator does not manage adapter transactions. If an adapter allocates multiple blocks and a later operation fails, rollback of those allocations is the adapter's responsibility.
|
|
336
|
+
|
|
337
|
+
Example:
|
|
338
|
+
|
|
339
|
+
```js
|
|
340
|
+
import Balloc from "balloc";
|
|
341
|
+
|
|
342
|
+
const allocator = new Balloc(65535, "8u");
|
|
343
|
+
const handler = allocator.loadData({
|
|
344
|
+
load(allocator) {
|
|
345
|
+
const handler = allocator.alloc(4);
|
|
346
|
+
allocator.put(handler, new Uint8Array([255, 0, 0, 255]));
|
|
347
|
+
return handler;
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
Format-specific adapters can be published independently. For example, `imagedata-adapter` ingests RGBA8 `ImageData` instances.
|
|
353
|
+
|
|
324
354
|
### Lifecycle
|
|
325
355
|
|
|
326
356
|
| API | Description |
|
|
@@ -430,7 +460,7 @@ If you like this project and want to support its development:
|
|
|
430
460
|
|
|
431
461
|
| Pix QR Code | Copy-and-Paste / Random Key |
|
|
432
462
|
| :---: | :--- |
|
|
433
|
-
|  | **Random Key:**<br>`e87d773a-0b97-4410-8fc3-f7ec04cce6a2` |
|
|
463
|
+
|  | **Random Key:**<br>`e87d773a-0b97-4410-8fc3-f7ec04cce6a2` |
|
|
434
464
|
|
|
435
465
|
## License
|
|
436
466
|
|
package/README.es.md
CHANGED
|
@@ -284,6 +284,7 @@ La documentación completa de la API está disponible en la carpeta [`./docs`](.
|
|
|
284
284
|
Los métodos de la API están agrupados por afinidad:
|
|
285
285
|
|
|
286
286
|
* Ciclo de vida
|
|
287
|
+
* Adaptadores de ingesta de datos
|
|
287
288
|
* Operaciones sobre pilas
|
|
288
289
|
* Operaciones sobre colas
|
|
289
290
|
* Operaciones sobre arrays
|
|
@@ -294,6 +295,35 @@ Los métodos de la API están agrupados por afinidad:
|
|
|
294
295
|
|
|
295
296
|
A continuación, un resumen de estos grupos:
|
|
296
297
|
|
|
298
|
+
### Adaptadores de ingesta de datos
|
|
299
|
+
|
|
300
|
+
`loadData(adapter)` delega la ingesta síncrona de datos a un adaptador que implementa el contrato `FormatAdapter`. El adaptador recibe el asignador y devuelve el handler numérico del bloque principal que carga.
|
|
301
|
+
|
|
302
|
+
```ts
|
|
303
|
+
interface FormatAdapter {
|
|
304
|
+
load(allocator: Balloc): number;
|
|
305
|
+
}
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
El asignador no administra las transacciones del adaptador. Si el adaptador asigna varios bloques y una operación posterior falla, el propio adaptador es responsable de revertir esas asignaciones.
|
|
309
|
+
|
|
310
|
+
Ejemplo:
|
|
311
|
+
|
|
312
|
+
```js
|
|
313
|
+
import Balloc from "balloc";
|
|
314
|
+
|
|
315
|
+
const allocator = new Balloc(65535, "8u");
|
|
316
|
+
const handler = allocator.loadData({
|
|
317
|
+
load(allocator) {
|
|
318
|
+
const handler = allocator.alloc(4);
|
|
319
|
+
allocator.put(handler, new Uint8Array([255, 0, 0, 255]));
|
|
320
|
+
return handler;
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
Los adaptadores específicos de cada formato pueden publicarse de forma independiente. Por ejemplo, `imagedata-adapter` ingiere instancias `ImageData` en formato RGBA8.
|
|
326
|
+
|
|
297
327
|
### Ciclo de vida
|
|
298
328
|
|
|
299
329
|
| API | Descripción |
|
|
@@ -402,7 +432,7 @@ Si te gusta este proyecto y quieres apoyar su desarrollo:
|
|
|
402
432
|
|
|
403
433
|
| QR Code Pix | Clave Copia y Pega / Aleatoria |
|
|
404
434
|
| :---: | :--- |
|
|
405
|
-
|  | **Clave Aleatoria:**<br>`e87d773a-0b97-4410-8fc3-f7ec04cce6a2` |
|
|
435
|
+
|  | **Clave Aleatoria:**<br>`e87d773a-0b97-4410-8fc3-f7ec04cce6a2` |
|
|
406
436
|
|
|
407
437
|
## Licencia
|
|
408
438
|
|
package/README.jp.md
CHANGED
|
@@ -283,6 +283,7 @@ APIの完全なドキュメントは[`./docs`](./docs)フォルダーにあり
|
|
|
283
283
|
APIメソッドは機能ごとに次のグループに分類されています。
|
|
284
284
|
|
|
285
285
|
* ライフサイクル
|
|
286
|
+
* データ取り込みアダプター
|
|
286
287
|
* スタック操作
|
|
287
288
|
* キュー操作
|
|
288
289
|
* 配列操作
|
|
@@ -293,6 +294,35 @@ APIメソッドは機能ごとに次のグループに分類されています
|
|
|
293
294
|
|
|
294
295
|
各グループの概要は次のとおりです。
|
|
295
296
|
|
|
297
|
+
### データ取り込みアダプター
|
|
298
|
+
|
|
299
|
+
`loadData(adapter)` は、`FormatAdapter` 契約を実装するアダプターに同期的なデータ取り込みを委譲します。アダプターはアロケーターを受け取り、読み込んだ主要ブロックの数値ハンドラーを返します。
|
|
300
|
+
|
|
301
|
+
```ts
|
|
302
|
+
interface FormatAdapter {
|
|
303
|
+
load(allocator: Balloc): number;
|
|
304
|
+
}
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
アロケーターはアダプターのトランザクションを管理しません。アダプターが複数のブロックを割り当てた後、後続の処理が失敗した場合、それらの割り当てをロールバックする責任はアダプター側にあります。
|
|
308
|
+
|
|
309
|
+
例:
|
|
310
|
+
|
|
311
|
+
```js
|
|
312
|
+
import Balloc from "balloc";
|
|
313
|
+
|
|
314
|
+
const allocator = new Balloc(65535, "8u");
|
|
315
|
+
const handler = allocator.loadData({
|
|
316
|
+
load(allocator) {
|
|
317
|
+
const handler = allocator.alloc(4);
|
|
318
|
+
allocator.put(handler, new Uint8Array([255, 0, 0, 255]));
|
|
319
|
+
return handler;
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
フォーマット固有のアダプターは個別に公開できます。たとえば、`imagedata-adapter` は RGBA8 形式の `ImageData` インスタンスを取り込みます。
|
|
325
|
+
|
|
296
326
|
### ライフサイクル
|
|
297
327
|
|
|
298
328
|
| API | 説明 |
|
|
@@ -401,7 +431,7 @@ APIメソッドは機能ごとに次のグループに分類されています
|
|
|
401
431
|
|
|
402
432
|
| Pix QRコード | コピー&ペースト用キー/ランダムキー |
|
|
403
433
|
| :---: | :--- |
|
|
404
|
-
|  | **ランダムキー:**<br>`e87d773a-0b97-4410-8fc3-f7ec04cce6a2` |
|
|
434
|
+
|  | **ランダムキー:**<br>`e87d773a-0b97-4410-8fc3-f7ec04cce6a2` |
|
|
405
435
|
|
|
406
436
|
## ライセンス
|
|
407
437
|
|
package/README.pt.md
CHANGED
|
@@ -85,28 +85,28 @@ A geração é utilizada pelo mecanismo de validação de *cookie* do alocador p
|
|
|
85
85
|
No Node.js instale o seguinte pacote NPM:
|
|
86
86
|
|
|
87
87
|
```bash
|
|
88
|
-
npm install
|
|
88
|
+
npm install balloc
|
|
89
89
|
|
|
90
90
|
```
|
|
91
91
|
|
|
92
92
|
No Bun instale:
|
|
93
93
|
|
|
94
94
|
```bash
|
|
95
|
-
bun add
|
|
95
|
+
bun add balloc
|
|
96
96
|
|
|
97
97
|
```
|
|
98
98
|
|
|
99
99
|
No Deno instale:
|
|
100
100
|
|
|
101
101
|
```bash
|
|
102
|
-
deno add npm:
|
|
102
|
+
deno add npm:balloc
|
|
103
103
|
|
|
104
104
|
```
|
|
105
105
|
|
|
106
106
|
Usando Yarn:
|
|
107
107
|
|
|
108
108
|
```bash
|
|
109
|
-
yarn add
|
|
109
|
+
yarn add balloc
|
|
110
110
|
|
|
111
111
|
```
|
|
112
112
|
|
|
@@ -151,7 +151,7 @@ Chinês: [https://cdn.jsdelivr.net/npm/Balloc/src/zh/Balloc.mjs](https://cdn.j
|
|
|
151
151
|
ESM:
|
|
152
152
|
|
|
153
153
|
```js
|
|
154
|
-
import Balloc from "
|
|
154
|
+
import Balloc from "balloc";
|
|
155
155
|
|
|
156
156
|
const memory = new Balloc();
|
|
157
157
|
|
|
@@ -174,7 +174,7 @@ memory.free(handler);
|
|
|
174
174
|
CJS:
|
|
175
175
|
|
|
176
176
|
```js
|
|
177
|
-
const Balloc = require("
|
|
177
|
+
const Balloc = require("balloc").default;
|
|
178
178
|
|
|
179
179
|
const memory = new Balloc();
|
|
180
180
|
|
|
@@ -321,6 +321,35 @@ Os métodos da API estão agrupados por afinidade e os grupos são:
|
|
|
321
321
|
|
|
322
322
|
Segue um resumo desses agrupamentos:
|
|
323
323
|
|
|
324
|
+
### Adaptadores de ingestão de dados
|
|
325
|
+
|
|
326
|
+
`loadData(adapter)` delega a ingestão síncrona de dados a um adaptador que implementa o contrato `FormatAdapter`. O adaptador recebe o alocador e retorna o handler numérico do bloco principal que carregou.
|
|
327
|
+
|
|
328
|
+
```ts
|
|
329
|
+
interface FormatAdapter {
|
|
330
|
+
load(allocator: Balloc): number;
|
|
331
|
+
}
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
O alocador não gerencia transações dos adaptadores. Se um adaptador alocar vários blocos e uma operação posterior falhar, a reversão dessas alocações é responsabilidade do próprio adaptador.
|
|
335
|
+
|
|
336
|
+
Exemplo:
|
|
337
|
+
|
|
338
|
+
```js
|
|
339
|
+
import Balloc from "balloc";
|
|
340
|
+
|
|
341
|
+
const allocator = new Balloc(65535, "8u");
|
|
342
|
+
const handler = allocator.loadData({
|
|
343
|
+
load(allocator) {
|
|
344
|
+
const handler = allocator.alloc(4);
|
|
345
|
+
allocator.put(handler, new Uint8Array([255, 0, 0, 255]));
|
|
346
|
+
return handler;
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
Adaptadores específicos de formato podem ser publicados independentemente. Por exemplo, `imagedata-adapter` faz a ingestão de instâncias `ImageData` no formato RGBA8.
|
|
352
|
+
|
|
324
353
|
### Ciclo de vida
|
|
325
354
|
|
|
326
355
|
| API | Descrição |
|
|
@@ -426,7 +455,7 @@ Se você gosta deste projeto e quer apoiar o seu desenvolvimento:
|
|
|
426
455
|
|
|
427
456
|
| QR Code Pix | Chave Copia e Cola / Aleatória |
|
|
428
457
|
| :---: | :--- |
|
|
429
|
-
|  | **Chave Aleatória:**<br>`e87d773a-0b97-4410-8fc3-f7ec04cce6a2` |
|
|
458
|
+
|  | **Chave Aleatória:**<br>`e87d773a-0b97-4410-8fc3-f7ec04cce6a2` |
|
|
430
459
|
|
|
431
460
|
## Licença
|
|
432
461
|
|
package/README.zh.md
CHANGED
|
@@ -283,6 +283,7 @@ Balloc 提供以下几种数据访问模型:
|
|
|
283
283
|
API 方法按功能归为以下类别:
|
|
284
284
|
|
|
285
285
|
* 生命周期管理
|
|
286
|
+
* 数据摄取适配器
|
|
286
287
|
* 栈操作
|
|
287
288
|
* 队列操作
|
|
288
289
|
* 数组操作
|
|
@@ -293,6 +294,35 @@ API 方法按功能归为以下类别:
|
|
|
293
294
|
|
|
294
295
|
各类别概述如下。
|
|
295
296
|
|
|
297
|
+
### 数据摄取适配器
|
|
298
|
+
|
|
299
|
+
`loadData(adapter)` 将同步数据摄取委托给实现 `FormatAdapter` 契约的适配器。适配器接收分配器实例,并返回其所加载主数据块的数字句柄。
|
|
300
|
+
|
|
301
|
+
```ts
|
|
302
|
+
interface FormatAdapter {
|
|
303
|
+
load(allocator: Balloc): number;
|
|
304
|
+
}
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
分配器不管理适配器事务。如果适配器分配了多个数据块,而后续操作失败,则由适配器负责回滚这些分配。
|
|
308
|
+
|
|
309
|
+
示例:
|
|
310
|
+
|
|
311
|
+
```js
|
|
312
|
+
import Balloc from "balloc";
|
|
313
|
+
|
|
314
|
+
const allocator = new Balloc(65535, "8u");
|
|
315
|
+
const handler = allocator.loadData({
|
|
316
|
+
load(allocator) {
|
|
317
|
+
const handler = allocator.alloc(4);
|
|
318
|
+
allocator.put(handler, new Uint8Array([255, 0, 0, 255]));
|
|
319
|
+
return handler;
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
特定格式的适配器可以独立发布。例如,`imagedata-adapter` 用于摄取 RGBA8 格式的 `ImageData` 实例。
|
|
325
|
+
|
|
296
326
|
### 生命周期管理
|
|
297
327
|
|
|
298
328
|
| API | 说明 |
|
|
@@ -401,7 +431,7 @@ API 方法按功能归为以下类别:
|
|
|
401
431
|
|
|
402
432
|
| Pix 二维码 | 复制粘贴密钥/随机密钥 |
|
|
403
433
|
| :---: | :--- |
|
|
404
|
-
|  | **随机密钥:**<br>`e87d773a-0b97-4410-8fc3-f7ec04cce6a2` |
|
|
434
|
+
|  | **随机密钥:**<br>`e87d773a-0b97-4410-8fc3-f7ec04cce6a2` |
|
|
405
435
|
|
|
406
436
|
## 许可证
|
|
407
437
|
|
|
@@ -25,6 +25,10 @@ Balloc
|
|
|
25
25
|
│ ├── free()
|
|
26
26
|
│ └── gc()
|
|
27
27
|
│
|
|
28
|
+
├── استيعاب البيانات
|
|
29
|
+
│ └── loadData()
|
|
30
|
+
│
|
|
31
|
+
│
|
|
28
32
|
├── الهياكل الخطية
|
|
29
33
|
│ ├── Stack
|
|
30
34
|
│ │ ├── push()
|
|
@@ -453,6 +457,57 @@ memory.gc();
|
|
|
453
457
|
|
|
454
458
|
---
|
|
455
459
|
|
|
460
|
+
## `loadData(adapter)`
|
|
461
|
+
|
|
462
|
+
يفوّض إدخال البيانات المتزامن إلى محوّل خاص بالتنسيق. يتلقى المحوّل مثيل `Balloc` الحالي، ويستخدم واجهته العامة لتخصيص الكتل وملئها، ثم يعيد المعالج الرقمي الذي يحدد الكتلة الأساسية.
|
|
463
|
+
|
|
464
|
+
لا يفسّر Balloc تنسيق الإدخال ولا يدير معاملات المحوّل. تقع مسؤولية تحليل البيانات وتنظيم الكتل والتراجع عن أي تخصيصات أجراها المحوّل عند فشل الإدخال على المحوّل نفسه. وتنتقل الاستثناءات التي يطلقها المحوّل عبر `loadData()` دون تغيير.
|
|
465
|
+
|
|
466
|
+
### عقد المحوّل
|
|
467
|
+
|
|
468
|
+
```ts
|
|
469
|
+
interface FormatAdapter {
|
|
470
|
+
load(allocator: Balloc): number;
|
|
471
|
+
}
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
يجب أن تكتمل `load()` بشكل متزامن وأن تعيد معالج كتلة صالحًا. إعادة `Promise` لا تجعل الإدخال غير متزامن؛ إذ لا تنتظر `loadData()` الوعد ولا تحلّه.
|
|
475
|
+
|
|
476
|
+
### المعلمات
|
|
477
|
+
|
|
478
|
+
| المعلمة | النوع | الوصف |
|
|
479
|
+
| --- | --- | --- |
|
|
480
|
+
| `adapter` | `FormatAdapter` | محوّل يطبّق `load(allocator)`. |
|
|
481
|
+
|
|
482
|
+
### القيمة المرجعة
|
|
483
|
+
|
|
484
|
+
```text
|
|
485
|
+
number
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
المعالج الذي يعيده المحوّل، والذي يحدد الكتلة الأساسية التي تم تحميلها.
|
|
489
|
+
|
|
490
|
+
### الاستثناءات
|
|
491
|
+
|
|
492
|
+
- `TypeError` — إذا كان `adapter` مفقودًا أو لا يوفّر طريقة `load()` قابلة للاستدعاء.
|
|
493
|
+
- أي استثناء تطلقه طريقة `load()` في المحوّل ينتقل دون تغيير.
|
|
494
|
+
|
|
495
|
+
### مثال
|
|
496
|
+
|
|
497
|
+
```js
|
|
498
|
+
const handler = memory.loadData({
|
|
499
|
+
load(allocator) {
|
|
500
|
+
const handler = allocator.alloc(4);
|
|
501
|
+
allocator.put(handler, new Uint8Array([255, 0, 0, 255]));
|
|
502
|
+
return handler;
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
يمكن توزيع المحوّلات الخاصة بالتنسيقات كحزم مستقلة. على سبيل المثال، تحمّل حزمة `imagedata-adapter` كائنات `ImageData` بتنسيق RGBA8 إلى مخصّص `Balloc`.
|
|
508
|
+
|
|
509
|
+
---
|
|
510
|
+
|
|
456
511
|
# 3. الهياكل الخطية (Linear Structures)
|
|
457
512
|
|
|
458
513
|
يمكن استخدام الكتل كهياكل خطية يتم الوصول إليها من الأطراف.
|
|
@@ -1407,6 +1462,7 @@ capacityBytes = 2 ** capacity × wordSize
|
|
|
1407
1462
|
| دورة الحياة | `shrink()` | `void`|
|
|
1408
1463
|
| دورة الحياة | `free()` | `void`|
|
|
1409
1464
|
| دورة الحياة | `gc()` | `void`|
|
|
1465
|
+
| استيعاب البيانات | `loadData()` | `number`|
|
|
1410
1466
|
| المكدس | `push()` | `boolean`|
|
|
1411
1467
|
| المكدس | `pop()` | `number |
|
|
1412
1468
|
| المكدس | `peek()` | `number |
|
|
@@ -31,6 +31,9 @@ Balloc
|
|
|
31
31
|
│ ├── free()
|
|
32
32
|
│ └── gc()
|
|
33
33
|
│
|
|
34
|
+
├── Data Ingestion
|
|
35
|
+
│ └── loadData()
|
|
36
|
+
│
|
|
34
37
|
├── Linear Structures
|
|
35
38
|
│ ├── Stack
|
|
36
39
|
│ │ ├── push()
|
|
@@ -439,6 +442,57 @@ memory.gc();
|
|
|
439
442
|
|
|
440
443
|
---
|
|
441
444
|
|
|
445
|
+
## `loadData(adapter)`
|
|
446
|
+
|
|
447
|
+
Delegates synchronous data ingestion to a format-specific adapter. The adapter receives the current `Balloc` instance, uses its public API to allocate and populate blocks, and returns the numeric handler identifying the primary block.
|
|
448
|
+
|
|
449
|
+
Balloc does not interpret the input format or manage adapter transactions. The adapter is responsible for data parsing, block organization, and rollback of any allocations it makes if ingestion fails. Exceptions thrown by the adapter propagate through `loadData()` unchanged.
|
|
450
|
+
|
|
451
|
+
### Adapter contract
|
|
452
|
+
|
|
453
|
+
```ts
|
|
454
|
+
interface FormatAdapter {
|
|
455
|
+
load(allocator: Balloc): number;
|
|
456
|
+
}
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
The `load()` method must complete synchronously and return a valid block handler. Returning a `Promise` does not make ingestion asynchronous; `loadData()` does not await or resolve it.
|
|
460
|
+
|
|
461
|
+
### Parameters
|
|
462
|
+
|
|
463
|
+
| Parameter | Type | Description |
|
|
464
|
+
| --- | --- | --- |
|
|
465
|
+
| `adapter` | `FormatAdapter` | Adapter implementing `load(allocator)`. |
|
|
466
|
+
|
|
467
|
+
### Return
|
|
468
|
+
|
|
469
|
+
```text
|
|
470
|
+
number
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
The handler returned by the adapter, identifying the primary block loaded.
|
|
474
|
+
|
|
475
|
+
### Exceptions
|
|
476
|
+
|
|
477
|
+
* `TypeError` — `adapter` is missing or does not provide a callable `load()` method.
|
|
478
|
+
* Any exception thrown by the adapter's `load()` method is propagated unchanged.
|
|
479
|
+
|
|
480
|
+
### Example
|
|
481
|
+
|
|
482
|
+
```js
|
|
483
|
+
const handler = memory.loadData({
|
|
484
|
+
load(allocator) {
|
|
485
|
+
const handler = allocator.alloc(4);
|
|
486
|
+
allocator.put(handler, new Uint8Array([255, 0, 0, 255]));
|
|
487
|
+
return handler;
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
Format-specific adapters can be distributed as independent packages. For example, `imagedata-adapter` loads RGBA8 `ImageData` instances into a `Balloc` allocator.
|
|
493
|
+
|
|
494
|
+
---
|
|
495
|
+
|
|
442
496
|
# 3. Linear Structures
|
|
443
497
|
|
|
444
498
|
Blocks can be used as linear structures accessed from the extremities.
|
|
@@ -1356,6 +1410,7 @@ Generation participates in cookie validation. Consequently, an invalid handler o
|
|
|
1356
1410
|
| Lifecycle | `shrink()` | `void`|
|
|
1357
1411
|
| Lifecycle | `free()` | `void`|
|
|
1358
1412
|
| Lifecycle | `gc()` | `void`|
|
|
1413
|
+
| Data ingestion | `loadData()` | `number`|
|
|
1359
1414
|
| Stack | `push()` | `boolean`|
|
|
1360
1415
|
| Stack | `pop()` | `number \| undefined` |
|
|
1361
1416
|
| Stack | `peek()` | `number \| undefined` |
|