@fuman/node
Advanced tools
+4
-4
| { | ||
| "name": "@fuman/node", | ||
| "type": "module", | ||
| "version": "0.0.17", | ||
| "version": "0.0.19", | ||
| "description": "node-specific utilities", | ||
@@ -9,5 +9,5 @@ "license": "MIT", | ||
| "dependencies": { | ||
| "@fuman/io": "^0.0.17", | ||
| "@fuman/net": "^0.0.17", | ||
| "@fuman/utils": "^0.0.17" | ||
| "@fuman/io": "^0.0.19", | ||
| "@fuman/net": "^0.0.19", | ||
| "@fuman/utils": "^0.0.19" | ||
| }, | ||
@@ -14,0 +14,0 @@ "peerDependencies": { |
| "use strict"; | ||
| Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); | ||
| const node_stream = require("node:stream"); | ||
| const io = require("@fuman/io"); | ||
| const utils = require("@fuman/utils"); | ||
@@ -20,5 +21,11 @@ function nodeReadableToFuman(stream) { | ||
| }); | ||
| const readBuffer = io.Bytes.alloc(); | ||
| return { | ||
| async read(into) { | ||
| if (stream.readableEnded) return 0; | ||
| if (readBuffer.available > 0) { | ||
| const size = Math.min(readBuffer.available, into.length); | ||
| into.set(readBuffer.readSync(size)); | ||
| return size; | ||
| } | ||
| let buf = null; | ||
@@ -34,2 +41,7 @@ while (buf == null) { | ||
| } | ||
| if (into.length < buf.length) { | ||
| const toReadBuffer = buf.length - into.length; | ||
| readBuffer.writeSync(toReadBuffer).set(buf.subarray(toReadBuffer)); | ||
| buf = buf.subarray(0, into.length); | ||
| } | ||
| into.set(buf); | ||
@@ -36,0 +48,0 @@ return buf.length; |
| import { Readable, Writable } from "node:stream"; | ||
| import { Bytes } from "@fuman/io"; | ||
| import { Deque, Deferred } from "@fuman/utils"; | ||
@@ -18,5 +19,11 @@ function nodeReadableToFuman(stream) { | ||
| }); | ||
| const readBuffer = Bytes.alloc(); | ||
| return { | ||
| async read(into) { | ||
| if (stream.readableEnded) return 0; | ||
| if (readBuffer.available > 0) { | ||
| const size = Math.min(readBuffer.available, into.length); | ||
| into.set(readBuffer.readSync(size)); | ||
| return size; | ||
| } | ||
| let buf = null; | ||
@@ -32,2 +39,7 @@ while (buf == null) { | ||
| } | ||
| if (into.length < buf.length) { | ||
| const toReadBuffer = buf.length - into.length; | ||
| readBuffer.writeSync(toReadBuffer).set(buf.subarray(toReadBuffer)); | ||
| buf = buf.subarray(0, into.length); | ||
| } | ||
| into.set(buf); | ||
@@ -34,0 +46,0 @@ return buf.length; |
62049
1.54%1760
1.38%+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
Updated
Updated
Updated