Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
@hazae41/binary
Advanced tools
Readme
npm i @hazae41/binary
class MyObject implements Writable {
constructor(
readonly x: number,
readonly y: number
) {}
size() {
return 1 + 2
}
write(cursor: Cursor): Result<void, Error> {
return Result.unthrowSync(() => {
cursor.tryWriteUint8(this.x).throw()
cursor.tryWriteUint16(this.y).throw()
return Ok.void()
})
}
}
const myobject = new MyObject(1, 515)
const bytes = Writable.tryWriteToBytes(myobject).unwrap() // Uint8Array([1, 2, 3])
class MyObject {
constructor(
readonly x: number,
readonly y: number
) {}
static read(cursor: Cursor): Result<MyObject, Error> {
return Result.unthrowSync(() => {
const x = cursor.tryReadUint8().throw()
const y = cursor.tryReadUint16().throw()
return new Ok(new this(x, y))
})
}
}
const bytes = new Uint8Array([1, 2, 3])
const myobject = Readable.tryReadFromBytes(MyObject, bytes).unwrap() // MyObject(1, 515)
This is a binary data type that just holds bytes, it can be used when a binary data type is required
const bytes = new Uint8Array([1, 2, 3])
const opaque = Readable.tryReadFromBytes(SafeOpaque, bytes).unwrap() // Opaque(Uint8Array([1, 2, 3]))
const myobject = opaque.tryInto(MyObject).unwrap() // MyObject(1, 515)
const myobject = new MyObject(1, 515)
const opaque = Opaque.tryWriteFrom(myobject).unwrap() // Opaque(Uint8Array([1, 2, 3]))
const bytes = Writable.tryWriteToBytes(opaque).unwrap() // Uint8Array([1, 2, 3])
FAQs
Zero-copy binary data types
We found that @hazae41/binary demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).