@fuman/io 0.0.11 → 0.0.14
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 +2 -2
- package/read/index.cjs +2 -0
- package/read/index.js +3 -1
- package/read/strings.cjs +25 -1
- package/read/strings.d.cts +3 -1
- package/read/strings.d.ts +3 -1
- package/read/strings.js +25 -1
- package/write/index.cjs +2 -0
- package/write/index.js +3 -1
- package/write/strings.cjs +20 -0
- package/write/strings.d.cts +4 -0
- package/write/strings.d.ts +4 -0
- package/write/strings.js +20 -0
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fuman/io",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.14",
|
|
5
5
|
"description": "experimental i/o abstractions",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"scripts": {},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@fuman/utils": "^0.0.
|
|
9
|
+
"@fuman/utils": "^0.0.14"
|
|
10
10
|
},
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
package/read/index.cjs
CHANGED
|
@@ -37,4 +37,6 @@ exports.rawString = strings.rawString;
|
|
|
37
37
|
exports.untilCondition = strings.untilCondition;
|
|
38
38
|
exports.untilEnd = strings.untilEnd;
|
|
39
39
|
exports.untilZero = strings.untilZero;
|
|
40
|
+
exports.utf16beString = strings.utf16beString;
|
|
41
|
+
exports.utf16leString = strings.utf16leString;
|
|
40
42
|
exports.utf8String = strings.utf8String;
|
package/read/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as index from "./async/index.js";
|
|
2
2
|
import { float32be, float32le, float64be, float64le, int16be, int16le, int24be, int24le, int32be, int32le, int64be, int64le, int8, intbe, intle, uint16be, uint16le, uint24be, uint24le, uint32be, uint32le, uint64be, uint64le, uint8, uintbe, uintle } from "./numbers.js";
|
|
3
|
-
import { cUtf8String, exactly, lengthPrefixed, rawString, untilCondition, untilEnd, untilZero, utf8String } from "./strings.js";
|
|
3
|
+
import { cUtf8String, exactly, lengthPrefixed, rawString, untilCondition, untilEnd, untilZero, utf16beString, utf16leString, utf8String } from "./strings.js";
|
|
4
4
|
export {
|
|
5
5
|
index as async,
|
|
6
6
|
cUtf8String,
|
|
@@ -36,5 +36,7 @@ export {
|
|
|
36
36
|
untilCondition,
|
|
37
37
|
untilEnd,
|
|
38
38
|
untilZero,
|
|
39
|
+
utf16beString,
|
|
40
|
+
utf16leString,
|
|
39
41
|
utf8String
|
|
40
42
|
};
|
package/read/strings.cjs
CHANGED
|
@@ -11,7 +11,7 @@ function exactly(readable, length) {
|
|
|
11
11
|
return buf;
|
|
12
12
|
}
|
|
13
13
|
function rawString(readable, length) {
|
|
14
|
-
const buf = exactly(readable, length);
|
|
14
|
+
const buf = readable instanceof Uint8Array ? readable : exactly(readable, length);
|
|
15
15
|
let result = "";
|
|
16
16
|
for (let i = 0; i < length; i++) {
|
|
17
17
|
result += String.fromCharCode(buf[i]);
|
|
@@ -21,6 +21,28 @@ function rawString(readable, length) {
|
|
|
21
21
|
function utf8String(readable, length) {
|
|
22
22
|
return utils.utf8.decoder.decode(exactly(readable, length));
|
|
23
23
|
}
|
|
24
|
+
function utf16beString(readable, byteLength) {
|
|
25
|
+
if (byteLength % 2 !== 0) {
|
|
26
|
+
throw new Error("utf16beString: byteLength must be even");
|
|
27
|
+
}
|
|
28
|
+
const buf = readable instanceof Uint8Array ? readable : exactly(readable, byteLength);
|
|
29
|
+
let result = "";
|
|
30
|
+
for (let i = 0; i < byteLength; i += 2) {
|
|
31
|
+
result += String.fromCharCode(buf[i + 1] | buf[i] << 8);
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
function utf16leString(readable, byteLength) {
|
|
36
|
+
if (byteLength % 2 !== 0) {
|
|
37
|
+
throw new Error("utf16leString: byteLength must be even");
|
|
38
|
+
}
|
|
39
|
+
const buf = readable instanceof Uint8Array ? readable : exactly(readable, byteLength);
|
|
40
|
+
let result = "";
|
|
41
|
+
for (let i = 0; i < byteLength; i += 2) {
|
|
42
|
+
result += String.fromCharCode(buf[i] | buf[i + 1] << 8);
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
24
46
|
function untilCondition(readable, condition) {
|
|
25
47
|
const buf = bytes.Bytes.alloc();
|
|
26
48
|
while (true) {
|
|
@@ -64,4 +86,6 @@ exports.rawString = rawString;
|
|
|
64
86
|
exports.untilCondition = untilCondition;
|
|
65
87
|
exports.untilEnd = untilEnd;
|
|
66
88
|
exports.untilZero = untilZero;
|
|
89
|
+
exports.utf16beString = utf16beString;
|
|
90
|
+
exports.utf16leString = utf16leString;
|
|
67
91
|
exports.utf8String = utf8String;
|
package/read/strings.d.cts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { ISyncReadable } from '../types.js';
|
|
2
2
|
export declare function exactly(readable: ISyncReadable, length: number): Uint8Array;
|
|
3
|
-
export declare function rawString(readable: ISyncReadable, length: number): string;
|
|
3
|
+
export declare function rawString(readable: ISyncReadable | Uint8Array, length: number): string;
|
|
4
4
|
export declare function utf8String(readable: ISyncReadable, length: number): string;
|
|
5
|
+
export declare function utf16beString(readable: ISyncReadable | Uint8Array, byteLength: number): string;
|
|
6
|
+
export declare function utf16leString(readable: ISyncReadable | Uint8Array, byteLength: number): string;
|
|
5
7
|
export declare function untilCondition(readable: ISyncReadable, condition: (byte: number) => boolean): Uint8Array;
|
|
6
8
|
export declare function untilEnd(readable: ISyncReadable, chunkSize?: number): Uint8Array;
|
|
7
9
|
export declare function untilZero(readable: ISyncReadable): Uint8Array;
|
package/read/strings.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { ISyncReadable } from '../types.js';
|
|
2
2
|
export declare function exactly(readable: ISyncReadable, length: number): Uint8Array;
|
|
3
|
-
export declare function rawString(readable: ISyncReadable, length: number): string;
|
|
3
|
+
export declare function rawString(readable: ISyncReadable | Uint8Array, length: number): string;
|
|
4
4
|
export declare function utf8String(readable: ISyncReadable, length: number): string;
|
|
5
|
+
export declare function utf16beString(readable: ISyncReadable | Uint8Array, byteLength: number): string;
|
|
6
|
+
export declare function utf16leString(readable: ISyncReadable | Uint8Array, byteLength: number): string;
|
|
5
7
|
export declare function untilCondition(readable: ISyncReadable, condition: (byte: number) => boolean): Uint8Array;
|
|
6
8
|
export declare function untilEnd(readable: ISyncReadable, chunkSize?: number): Uint8Array;
|
|
7
9
|
export declare function untilZero(readable: ISyncReadable): Uint8Array;
|
package/read/strings.js
CHANGED
|
@@ -9,7 +9,7 @@ function exactly(readable, length) {
|
|
|
9
9
|
return buf;
|
|
10
10
|
}
|
|
11
11
|
function rawString(readable, length) {
|
|
12
|
-
const buf = exactly(readable, length);
|
|
12
|
+
const buf = readable instanceof Uint8Array ? readable : exactly(readable, length);
|
|
13
13
|
let result = "";
|
|
14
14
|
for (let i = 0; i < length; i++) {
|
|
15
15
|
result += String.fromCharCode(buf[i]);
|
|
@@ -19,6 +19,28 @@ function rawString(readable, length) {
|
|
|
19
19
|
function utf8String(readable, length) {
|
|
20
20
|
return utf8.decoder.decode(exactly(readable, length));
|
|
21
21
|
}
|
|
22
|
+
function utf16beString(readable, byteLength) {
|
|
23
|
+
if (byteLength % 2 !== 0) {
|
|
24
|
+
throw new Error("utf16beString: byteLength must be even");
|
|
25
|
+
}
|
|
26
|
+
const buf = readable instanceof Uint8Array ? readable : exactly(readable, byteLength);
|
|
27
|
+
let result = "";
|
|
28
|
+
for (let i = 0; i < byteLength; i += 2) {
|
|
29
|
+
result += String.fromCharCode(buf[i + 1] | buf[i] << 8);
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
function utf16leString(readable, byteLength) {
|
|
34
|
+
if (byteLength % 2 !== 0) {
|
|
35
|
+
throw new Error("utf16leString: byteLength must be even");
|
|
36
|
+
}
|
|
37
|
+
const buf = readable instanceof Uint8Array ? readable : exactly(readable, byteLength);
|
|
38
|
+
let result = "";
|
|
39
|
+
for (let i = 0; i < byteLength; i += 2) {
|
|
40
|
+
result += String.fromCharCode(buf[i] | buf[i + 1] << 8);
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
22
44
|
function untilCondition(readable, condition) {
|
|
23
45
|
const buf = Bytes.alloc();
|
|
24
46
|
while (true) {
|
|
@@ -63,5 +85,7 @@ export {
|
|
|
63
85
|
untilCondition,
|
|
64
86
|
untilEnd,
|
|
65
87
|
untilZero,
|
|
88
|
+
utf16beString,
|
|
89
|
+
utf16leString,
|
|
66
90
|
utf8String
|
|
67
91
|
};
|
package/write/index.cjs
CHANGED
|
@@ -34,4 +34,6 @@ exports.bytes = strings.bytes;
|
|
|
34
34
|
exports.bytesReversed = strings.bytesReversed;
|
|
35
35
|
exports.cUtf8String = strings.cUtf8String;
|
|
36
36
|
exports.rawString = strings.rawString;
|
|
37
|
+
exports.utf16beString = strings.utf16beString;
|
|
38
|
+
exports.utf16leString = strings.utf16leString;
|
|
37
39
|
exports.utf8String = strings.utf8String;
|
package/write/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { float32be, float32le, float64be, float64le, int16be, int16le, int24be, int24le, int32be, int32le, int64be, int64le, int8, intbe, intle, uint16be, uint16le, uint24be, uint24le, uint32be, uint32le, uint64be, uint64le, uint8, uintbe, uintle } from "./numbers.js";
|
|
2
2
|
import { pipe } from "./pipe.js";
|
|
3
|
-
import { bytes, bytesReversed, cUtf8String, rawString, utf8String } from "./strings.js";
|
|
3
|
+
import { bytes, bytesReversed, cUtf8String, rawString, utf16beString, utf16leString, utf8String } from "./strings.js";
|
|
4
4
|
export {
|
|
5
5
|
bytes,
|
|
6
6
|
bytesReversed,
|
|
@@ -33,5 +33,7 @@ export {
|
|
|
33
33
|
uint8,
|
|
34
34
|
uintbe,
|
|
35
35
|
uintle,
|
|
36
|
+
utf16beString,
|
|
37
|
+
utf16leString,
|
|
36
38
|
utf8String
|
|
37
39
|
};
|
package/write/strings.cjs
CHANGED
|
@@ -24,6 +24,24 @@ function utf8String(writable, str) {
|
|
|
24
24
|
utils.utf8.encoder.encodeInto(str, buf);
|
|
25
25
|
writable.disposeWriteSync();
|
|
26
26
|
}
|
|
27
|
+
function utf16beString(writable, str) {
|
|
28
|
+
const buf = writable.writeSync(str.length * 2);
|
|
29
|
+
for (let i = 0, j = 0; i < str.length; i++, j += 2) {
|
|
30
|
+
const char = str.charCodeAt(i);
|
|
31
|
+
buf[j + 1] = char & 255;
|
|
32
|
+
buf[j] = char >> 8 & 255;
|
|
33
|
+
}
|
|
34
|
+
writable.disposeWriteSync();
|
|
35
|
+
}
|
|
36
|
+
function utf16leString(writable, str) {
|
|
37
|
+
const buf = writable.writeSync(str.length * 2);
|
|
38
|
+
for (let i = 0, j = 0; i < str.length; i++, j += 2) {
|
|
39
|
+
const char = str.charCodeAt(i);
|
|
40
|
+
buf[j] = char & 255;
|
|
41
|
+
buf[j + 1] = char >> 8 & 255;
|
|
42
|
+
}
|
|
43
|
+
writable.disposeWriteSync();
|
|
44
|
+
}
|
|
27
45
|
function cUtf8String(writable, str) {
|
|
28
46
|
const len = utils.utf8.encodedLength(str);
|
|
29
47
|
const buf = writable.writeSync(len + 1);
|
|
@@ -35,4 +53,6 @@ exports.bytes = bytes;
|
|
|
35
53
|
exports.bytesReversed = bytesReversed;
|
|
36
54
|
exports.cUtf8String = cUtf8String;
|
|
37
55
|
exports.rawString = rawString;
|
|
56
|
+
exports.utf16beString = utf16beString;
|
|
57
|
+
exports.utf16leString = utf16leString;
|
|
38
58
|
exports.utf8String = utf8String;
|
package/write/strings.d.cts
CHANGED
|
@@ -7,5 +7,9 @@ export declare function bytesReversed(writable: ISyncWritable, bytes: Uint8Array
|
|
|
7
7
|
export declare function rawString(writable: ISyncWritable, str: string): void;
|
|
8
8
|
/** write a utf8-encoded string to the stream */
|
|
9
9
|
export declare function utf8String(writable: ISyncWritable, str: string): void;
|
|
10
|
+
/** write a utf16-encoded string to the stream */
|
|
11
|
+
export declare function utf16beString(writable: ISyncWritable, str: string): void;
|
|
12
|
+
/** write a utf16-encoded string to the stream */
|
|
13
|
+
export declare function utf16leString(writable: ISyncWritable, str: string): void;
|
|
10
14
|
/** write a utf8-encoded string to the stream, with a null terminator */
|
|
11
15
|
export declare function cUtf8String(writable: ISyncWritable, str: string): void;
|
package/write/strings.d.ts
CHANGED
|
@@ -7,5 +7,9 @@ export declare function bytesReversed(writable: ISyncWritable, bytes: Uint8Array
|
|
|
7
7
|
export declare function rawString(writable: ISyncWritable, str: string): void;
|
|
8
8
|
/** write a utf8-encoded string to the stream */
|
|
9
9
|
export declare function utf8String(writable: ISyncWritable, str: string): void;
|
|
10
|
+
/** write a utf16-encoded string to the stream */
|
|
11
|
+
export declare function utf16beString(writable: ISyncWritable, str: string): void;
|
|
12
|
+
/** write a utf16-encoded string to the stream */
|
|
13
|
+
export declare function utf16leString(writable: ISyncWritable, str: string): void;
|
|
10
14
|
/** write a utf8-encoded string to the stream, with a null terminator */
|
|
11
15
|
export declare function cUtf8String(writable: ISyncWritable, str: string): void;
|
package/write/strings.js
CHANGED
|
@@ -22,6 +22,24 @@ function utf8String(writable, str) {
|
|
|
22
22
|
utf8.encoder.encodeInto(str, buf);
|
|
23
23
|
writable.disposeWriteSync();
|
|
24
24
|
}
|
|
25
|
+
function utf16beString(writable, str) {
|
|
26
|
+
const buf = writable.writeSync(str.length * 2);
|
|
27
|
+
for (let i = 0, j = 0; i < str.length; i++, j += 2) {
|
|
28
|
+
const char = str.charCodeAt(i);
|
|
29
|
+
buf[j + 1] = char & 255;
|
|
30
|
+
buf[j] = char >> 8 & 255;
|
|
31
|
+
}
|
|
32
|
+
writable.disposeWriteSync();
|
|
33
|
+
}
|
|
34
|
+
function utf16leString(writable, str) {
|
|
35
|
+
const buf = writable.writeSync(str.length * 2);
|
|
36
|
+
for (let i = 0, j = 0; i < str.length; i++, j += 2) {
|
|
37
|
+
const char = str.charCodeAt(i);
|
|
38
|
+
buf[j] = char & 255;
|
|
39
|
+
buf[j + 1] = char >> 8 & 255;
|
|
40
|
+
}
|
|
41
|
+
writable.disposeWriteSync();
|
|
42
|
+
}
|
|
25
43
|
function cUtf8String(writable, str) {
|
|
26
44
|
const len = utf8.encodedLength(str);
|
|
27
45
|
const buf = writable.writeSync(len + 1);
|
|
@@ -34,5 +52,7 @@ export {
|
|
|
34
52
|
bytesReversed,
|
|
35
53
|
cUtf8String,
|
|
36
54
|
rawString,
|
|
55
|
+
utf16beString,
|
|
56
|
+
utf16leString,
|
|
37
57
|
utf8String
|
|
38
58
|
};
|