Comments (7)
Do you want repo of whole this process?
from node.
+"\u0004" at write, and parsing on recieving socket solves the problem, but IMO it should be automatic, so reclassify this as feature request if you wish.
from node.
Do you want repo of whole this process?
Yes, providing reproduction steps (and code) is the best way for people to see and understand what went wrong
from node.
https://github.com/arreehm/socketConnector
I don't know if it's expected, but it mostly doesn't happen.
from node.
Like I understand, if it's sends in a buffer at one time it's two different thing, but I never managed to break the JSON.parse
being in on('data',
like that, I fixed it with unicode symbol, but anyhow, it feels broken.
from node.
Now I see, that I should write my own encoding, where there is size of JSON specified and read up buffer up to that length, but it takes away ease of javascript, I expected it to be done by default.
from node.
Solution I have is to encode/decode JSON String by following thing:
const { Buffer } = require('node:buffer')
const encode = (string, encoding)=>{
string = Buffer.from(string, encoding)
let length = string.byteLength
length = Buffer.from(`<${length}>`)
let buffer = Buffer.concat([length, string])
return buffer
}
const decode = (buffer, encoding, perChunk)=>{
let stop = false
while(!stop) {
let index = buffer.indexOf('>')
let sub = buffer.subarray(1, index)
let length = Number(sub.toString())
let ourChunk = buffer.subarray(index+1, length+index+1)
perChunk(ourChunk.toString())
buffer = buffer.subarray(length+index+1)
if(buffer.byteLength===0) stop = true
}
}
module.exports = (encoding)=>{
return {
encode: (string)=>{
return encode(string, encoding)
},
decode: (buffer, perChunk)=>{
return decode(buffer, encoding, perChunk)
}
}
}
from node.
Related Issues (20)
- Verify env parameter when napi_get_uv_event_loop functions is called. HOT 2
- TypeError: Missing internal module 'node:crypto' HOT 14
- Disable `NODE_OPTIONS` via CLI HOT 4
- Node 20 not supporting prepack script HOT 2
- Passing `-j32` for ninja no longer works HOT 24
- Tracking issue: latest ESM Integration support
- Module Hooks cannot be registered from worker thread in 22.2.0+ HOT 21
- [REG 20.9->20.10] stream: Pipe is stopped after error on another pipe from the same source HOT 5
- Update Undici to backport a fix in Node.js 20.x HOT 1
- Not able to download nodejs for windows HOT 1
- Unhandled Error on Start HOT 3
- Support registering worker specific custom ESM loader hooks (Regression from #52706) HOT 17
- Lambdas in node 18.x (18.20.3) and problems with axios HPE_INVALID_HEADER_TOKEN HOT 2
- Xcode
- Relative `require()` in `commonjs` source not processed by ESM Loader HOT 2
- test_runner: `before` hook runs even if it's not followed by any test HOT 7
- The registration order of http server listen depends on the Node.js version HOT 5
- Ambiguous steps in `PACKAGE_IMPORTS_EXPORTS_RESOLVE` reference documentation HOT 8
- Memory leak or GC overrun in sort() HOT 2
- (Discuss) `_stream_*`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node.