Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
@hazae41/binary
Advanced tools
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
The npm package @hazae41/binary receives a total of 25 weekly downloads. As such, @hazae41/binary popularity was classified as not popular.
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 0 open source maintainers 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
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.