+2
-2
| { | ||
| "name": "@fuman/io", | ||
| "type": "module", | ||
| "version": "0.0.11", | ||
| "version": "0.0.14", | ||
| "description": "experimental i/o abstractions", | ||
@@ -9,3 +9,3 @@ "license": "MIT", | ||
| "dependencies": { | ||
| "@fuman/utils": "^0.0.11" | ||
| "@fuman/utils": "^0.0.14" | ||
| }, | ||
@@ -12,0 +12,0 @@ "exports": { |
+2
-0
@@ -40,2 +40,4 @@ "use strict"; | ||
| exports.untilZero = strings.untilZero; | ||
| exports.utf16beString = strings.utf16beString; | ||
| exports.utf16leString = strings.utf16leString; | ||
| exports.utf8String = strings.utf8String; |
+3
-1
| import * as index from "./async/index.js"; | ||
| 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"; | ||
| import { cUtf8String, exactly, lengthPrefixed, rawString, untilCondition, untilEnd, untilZero, utf8String } from "./strings.js"; | ||
| import { cUtf8String, exactly, lengthPrefixed, rawString, untilCondition, untilEnd, untilZero, utf16beString, utf16leString, utf8String } from "./strings.js"; | ||
| export { | ||
@@ -39,3 +39,5 @@ index as async, | ||
| untilZero, | ||
| utf16beString, | ||
| utf16leString, | ||
| utf8String | ||
| }; |
+25
-1
@@ -14,3 +14,3 @@ "use strict"; | ||
| function rawString(readable, length) { | ||
| const buf = exactly(readable, length); | ||
| const buf = readable instanceof Uint8Array ? readable : exactly(readable, length); | ||
| let result = ""; | ||
@@ -25,2 +25,24 @@ for (let i = 0; i < length; i++) { | ||
| } | ||
| function utf16beString(readable, byteLength) { | ||
| if (byteLength % 2 !== 0) { | ||
| throw new Error("utf16beString: byteLength must be even"); | ||
| } | ||
| const buf = readable instanceof Uint8Array ? readable : exactly(readable, byteLength); | ||
| let result = ""; | ||
| for (let i = 0; i < byteLength; i += 2) { | ||
| result += String.fromCharCode(buf[i + 1] | buf[i] << 8); | ||
| } | ||
| return result; | ||
| } | ||
| function utf16leString(readable, byteLength) { | ||
| if (byteLength % 2 !== 0) { | ||
| throw new Error("utf16leString: byteLength must be even"); | ||
| } | ||
| const buf = readable instanceof Uint8Array ? readable : exactly(readable, byteLength); | ||
| let result = ""; | ||
| for (let i = 0; i < byteLength; i += 2) { | ||
| result += String.fromCharCode(buf[i] | buf[i + 1] << 8); | ||
| } | ||
| return result; | ||
| } | ||
| function untilCondition(readable, condition) { | ||
@@ -69,2 +91,4 @@ const buf = bytes.Bytes.alloc(); | ||
| exports.untilZero = untilZero; | ||
| exports.utf16beString = utf16beString; | ||
| exports.utf16leString = utf16leString; | ||
| exports.utf8String = utf8String; |
| import { ISyncReadable } from '../types.js'; | ||
| export declare function exactly(readable: ISyncReadable, length: number): Uint8Array; | ||
| export declare function rawString(readable: ISyncReadable, length: number): string; | ||
| export declare function rawString(readable: ISyncReadable | Uint8Array, length: number): string; | ||
| export declare function utf8String(readable: ISyncReadable, length: number): string; | ||
| export declare function utf16beString(readable: ISyncReadable | Uint8Array, byteLength: number): string; | ||
| export declare function utf16leString(readable: ISyncReadable | Uint8Array, byteLength: number): string; | ||
| export declare function untilCondition(readable: ISyncReadable, condition: (byte: number) => boolean): Uint8Array; | ||
@@ -6,0 +8,0 @@ export declare function untilEnd(readable: ISyncReadable, chunkSize?: number): Uint8Array; |
| import { ISyncReadable } from '../types.js'; | ||
| export declare function exactly(readable: ISyncReadable, length: number): Uint8Array; | ||
| export declare function rawString(readable: ISyncReadable, length: number): string; | ||
| export declare function rawString(readable: ISyncReadable | Uint8Array, length: number): string; | ||
| export declare function utf8String(readable: ISyncReadable, length: number): string; | ||
| export declare function utf16beString(readable: ISyncReadable | Uint8Array, byteLength: number): string; | ||
| export declare function utf16leString(readable: ISyncReadable | Uint8Array, byteLength: number): string; | ||
| export declare function untilCondition(readable: ISyncReadable, condition: (byte: number) => boolean): Uint8Array; | ||
@@ -6,0 +8,0 @@ export declare function untilEnd(readable: ISyncReadable, chunkSize?: number): Uint8Array; |
+25
-1
@@ -12,3 +12,3 @@ import { utf8 } from "@fuman/utils"; | ||
| function rawString(readable, length) { | ||
| const buf = exactly(readable, length); | ||
| const buf = readable instanceof Uint8Array ? readable : exactly(readable, length); | ||
| let result = ""; | ||
@@ -23,2 +23,24 @@ for (let i = 0; i < length; i++) { | ||
| } | ||
| function utf16beString(readable, byteLength) { | ||
| if (byteLength % 2 !== 0) { | ||
| throw new Error("utf16beString: byteLength must be even"); | ||
| } | ||
| const buf = readable instanceof Uint8Array ? readable : exactly(readable, byteLength); | ||
| let result = ""; | ||
| for (let i = 0; i < byteLength; i += 2) { | ||
| result += String.fromCharCode(buf[i + 1] | buf[i] << 8); | ||
| } | ||
| return result; | ||
| } | ||
| function utf16leString(readable, byteLength) { | ||
| if (byteLength % 2 !== 0) { | ||
| throw new Error("utf16leString: byteLength must be even"); | ||
| } | ||
| const buf = readable instanceof Uint8Array ? readable : exactly(readable, byteLength); | ||
| let result = ""; | ||
| for (let i = 0; i < byteLength; i += 2) { | ||
| result += String.fromCharCode(buf[i] | buf[i + 1] << 8); | ||
| } | ||
| return result; | ||
| } | ||
| function untilCondition(readable, condition) { | ||
@@ -68,3 +90,5 @@ const buf = Bytes.alloc(); | ||
| untilZero, | ||
| utf16beString, | ||
| utf16leString, | ||
| utf8String | ||
| }; |
+2
-0
@@ -37,2 +37,4 @@ "use strict"; | ||
| exports.rawString = strings.rawString; | ||
| exports.utf16beString = strings.utf16beString; | ||
| exports.utf16leString = strings.utf16leString; | ||
| exports.utf8String = strings.utf8String; |
+3
-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"; | ||
| import { pipe } from "./pipe.js"; | ||
| import { bytes, bytesReversed, cUtf8String, rawString, utf8String } from "./strings.js"; | ||
| import { bytes, bytesReversed, cUtf8String, rawString, utf16beString, utf16leString, utf8String } from "./strings.js"; | ||
| export { | ||
@@ -36,3 +36,5 @@ bytes, | ||
| uintle, | ||
| utf16beString, | ||
| utf16leString, | ||
| utf8String | ||
| }; |
+20
-0
@@ -27,2 +27,20 @@ "use strict"; | ||
| } | ||
| function utf16beString(writable, str) { | ||
| const buf = writable.writeSync(str.length * 2); | ||
| for (let i = 0, j = 0; i < str.length; i++, j += 2) { | ||
| const char = str.charCodeAt(i); | ||
| buf[j + 1] = char & 255; | ||
| buf[j] = char >> 8 & 255; | ||
| } | ||
| writable.disposeWriteSync(); | ||
| } | ||
| function utf16leString(writable, str) { | ||
| const buf = writable.writeSync(str.length * 2); | ||
| for (let i = 0, j = 0; i < str.length; i++, j += 2) { | ||
| const char = str.charCodeAt(i); | ||
| buf[j] = char & 255; | ||
| buf[j + 1] = char >> 8 & 255; | ||
| } | ||
| writable.disposeWriteSync(); | ||
| } | ||
| function cUtf8String(writable, str) { | ||
@@ -39,2 +57,4 @@ const len = utils.utf8.encodedLength(str); | ||
| exports.rawString = rawString; | ||
| exports.utf16beString = utf16beString; | ||
| exports.utf16leString = utf16leString; | ||
| exports.utf8String = utf8String; |
@@ -10,3 +10,7 @@ import { ISyncWritable } from '../types.js'; | ||
| export declare function utf8String(writable: ISyncWritable, str: string): void; | ||
| /** write a utf16-encoded string to the stream */ | ||
| export declare function utf16beString(writable: ISyncWritable, str: string): void; | ||
| /** write a utf16-encoded string to the stream */ | ||
| export declare function utf16leString(writable: ISyncWritable, str: string): void; | ||
| /** write a utf8-encoded string to the stream, with a null terminator */ | ||
| export declare function cUtf8String(writable: ISyncWritable, str: string): void; |
@@ -10,3 +10,7 @@ import { ISyncWritable } from '../types.js'; | ||
| export declare function utf8String(writable: ISyncWritable, str: string): void; | ||
| /** write a utf16-encoded string to the stream */ | ||
| export declare function utf16beString(writable: ISyncWritable, str: string): void; | ||
| /** write a utf16-encoded string to the stream */ | ||
| export declare function utf16leString(writable: ISyncWritable, str: string): void; | ||
| /** write a utf8-encoded string to the stream, with a null terminator */ | ||
| export declare function cUtf8String(writable: ISyncWritable, str: string): void; |
+20
-0
@@ -25,2 +25,20 @@ import { utf8 } from "@fuman/utils"; | ||
| } | ||
| function utf16beString(writable, str) { | ||
| const buf = writable.writeSync(str.length * 2); | ||
| for (let i = 0, j = 0; i < str.length; i++, j += 2) { | ||
| const char = str.charCodeAt(i); | ||
| buf[j + 1] = char & 255; | ||
| buf[j] = char >> 8 & 255; | ||
| } | ||
| writable.disposeWriteSync(); | ||
| } | ||
| function utf16leString(writable, str) { | ||
| const buf = writable.writeSync(str.length * 2); | ||
| for (let i = 0, j = 0; i < str.length; i++, j += 2) { | ||
| const char = str.charCodeAt(i); | ||
| buf[j] = char & 255; | ||
| buf[j + 1] = char >> 8 & 255; | ||
| } | ||
| writable.disposeWriteSync(); | ||
| } | ||
| function cUtf8String(writable, str) { | ||
@@ -38,3 +56,5 @@ const len = utf8.encodedLength(str); | ||
| rawString, | ||
| utf16beString, | ||
| utf16leString, | ||
| utf8String | ||
| }; |
145327
3%3720
2.82%+ Added
- Removed
Updated