diff options
author | 2022-04-06 01:52:15 -0700 | |
---|---|---|
committer | 2022-04-06 01:53:05 -0700 | |
commit | 81eb47de0eb08081ed0677b71aa47e9a2b473cab (patch) | |
tree | 051df34c66832ab2f0986370d5c8fbb3e12058fc /examples/mmap/2.js | |
parent | 57cf035a73187439fbcd8703d7f4358463ee8314 (diff) | |
download | bun-81eb47de0eb08081ed0677b71aa47e9a2b473cab.tar.gz bun-81eb47de0eb08081ed0677b71aa47e9a2b473cab.tar.zst bun-81eb47de0eb08081ed0677b71aa47e9a2b473cab.zip |
[bun.js] Add stdout, stderr, stdin to Bun and support sendfile() + splice()
Diffstat (limited to 'examples/mmap/2.js')
-rw-r--r-- | examples/mmap/2.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/examples/mmap/2.js b/examples/mmap/2.js new file mode 100644 index 000000000..c4b68bd9a --- /dev/null +++ b/examples/mmap/2.js @@ -0,0 +1,22 @@ +const map = Bun.mmap("./mmap.txt"); + +function buffer_hash(buffer) { + let hash = 0; + for (let i = 0; i < buffer.length; i++) { + hash = (hash << 5) - hash + buffer[i]; + hash |= 0; // Convert to 32bit integer + } + return hash; +} + +const decoder = new TextDecoder(); + +let hash = buffer_hash(map); +console.log(decoder.decode(map)); + +while (true) { + if (buffer_hash(map) !== hash) { + hash = buffer_hash(map); + console.log(`mmap changed to ~> ${decoder.decode(map)}`); + } +} |