Commit 76e066d5 authored by Will Hilton's avatar Will Hilton

Add putchar and putbuffer to the README.

parent faad86d7
......@@ -185,6 +185,25 @@ process incoming data, and send it to...
### stdout : pull-stream Sink
### putchar : (Number) => Number | Error EOF | undefined
Writes a single byte to `stdout`. Be fancy and write your numbers in hex! See examples/stdin/stdout-unbuffered.js
Should return the same number you gave it, the EOF error if stdout got closed (untested),
undefined if non-blocking write is supported and the output was temporarily unavailable (untested),
or throw an error from the underlying C layer.
### putbuffer : (Uint8Array) => Number | Error EOF | undefined
Unfortunately `putchar` pays for its simplicity by sacrificing speed.
Switching from the JS layer to the C layer and back again for every byte can
negatively impact performance if you have a lot of bytes to write.
The solution is to write bytes in batches! Lucky us, JavaScript has just such
a structure for efficiently passing multiple bytes at once, the Uint8Array.
See the examples/stdin/stdout-buffered.js which runs 36x faster than the unbuffered example.
(On my machine, your mileage may vary.)
Returns the number of bytes written, which is equal to the size of the buffer.
I might add support for start / end indices.
## Parallel Computing
By default, Dukboot will start as many physical threads as you have logical cores.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment