You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What would be the recommendation for specifying a delimiter when writing one binary object to a file at a time for the purpose of later processing as a node.js stream?
Can I simply write the binary data fs.writeFile with 'binary' with a trailing require('os').EOL? The end goal would be to read in a stream and decode in a transform with something like maxogden/binary-split or myndzi/binary-split-streams2
Choose one byte (or byte sequence) as delimiter, but escape matches that may happen inside de encoded binary on write and then unescape them on read.
Do not use any delimiter and rely on lower-level Type#read() function. This works because Type#read() only reads up to the end of one record, allowing you to call it multiple times to get multiple values
// Suppose `buffer` has potentially multiple (full) encoded values// `schema` is an Type instanceletReadState=require('js-binary').ReadState,rs=newReadState(buffer)while(!rs.hasEnded()){console.log(schema.read(rs))}
Activity
sitegui commentedon Apr 24, 2018
Hi @aaronpeterson ,
In general, there is no valid delimiter, since any arbitrary byte sequence can happen in the middle of some value. For example:
If you want to write multiple values into a file, I can give you 3 valid approaches:
Choose one byte (or byte sequence) as delimiter, but escape matches that may happen inside de encoded binary on write and then unescape them on read.
Do not use any delimiter and rely on lower-level Type#read() function. This works because Type#read() only reads up to the end of one record, allowing you to call it multiple times to get multiple values
Hope it works for you!