A callback that receives a possible error and, if no error occurred, a read type and value
A callback that receives a possible error and, if no error occurred, a read type
A callback that receives a possible error and, if no error occurred, a read value
Reads a type and a value from a readable stream.
This should be used when reading from sources
written to by writeTypeAndValue.
Calls callback
with the type and value when done.
Example:
//With a callback:
sb.readTypeAndValue(fs.createReadStream('out.sbtv'), (err, type, value) => {
if (err) throw err
console.log(type, value)
})
//As a Promise:
util.promisify(sb.readTypeAndValue)(fs.createReadStream('out.sbtv'))
.then(({type, value}) => console.log(type, value))
Responds to an HTTP(S) request for a value.
Will send both type and value if the sig
header
doesn't match the type's signature.
Will only send the value if the signatures match.
Response is gzipped to decrease size, if client allows.
Calls callback
when done.
Example:
sb.httpRespond({
req,
res,
type: new sb.DateType
value: new Date
})
The optional callback to call when response ends
Reads a type from a readable stream.
This should be used when reading from sources
written to by writeType.
Calls callback
with the type when done.
Example:
//With a callback:
sb.readType(fs.createReadStream('out.sbt'), (err, type) => {
if (err) throw err
console.log(type)
})
//As a Promise:
util.promisify(sb.readType)(fs.createReadStream('out.sbt'))
.then(type => console.log(type))
The stream to read from
The callback to call with the read result
Reads a value from a readable stream.
The Type used to write the value bytes must be known.
This should be used when reading from sources
written to by writeValue.
Calls callback
with the value when done.
Example:
//With a callback:
sb.readValue({
type: new sb.FlexUnsignedIntType,
inStream: fs.createReadStream('out.sbv')
}, (err, value) => {
if (err) throw err
console.log(value)
})
//As a Promise:
util.promisify(sb.readValue)({
type: new sb.FlexUnsignedIntType,
inStream: fs.createReadStream('out.sbv')
})
.then(value => console.log(value))
The type of value being read
(must match the VALUE
parameter of type
)
The callback to call with the read result
Writes the contents of type.toBuffer()
(Type.toBuffer)
to a writable stream and then closes the stream.
Calls callback
when done.
Example:
//With a callback:
sb.writeType({
type: new sb.StructType({
abc: new sb.ArrayType(new sb.StringType),
def: new sb.DateType
}),
outStream: fs.createWriteStream('out.sbt')
}, err => {
if (err) throw err
console.log('Done')
})
//As a Promise:
util.promisify(sb.writeType)({
type: new sb.StructType({
abc: new sb.ArrayType(new sb.StringType),
def: new sb.DateType
}),
outStream: fs.createWriteStream('out.sbt')
})
.then(_ => console.log('Done'))
The optional callback to call when write ends
outStream
Writes the contents of type.toBuffer()
(Type.toBuffer),
followed by the contents of type.valueBuffer(value)
(Type.valueBuffer),
to a writable stream and then closes the stream.
Calls callback
when done.
Example:
//With a callback:
sb.writeTypeAndValue({
type: new sb.FlexUnsignedIntType,
value: 1000,
outStream: fs.createWriteStream('out.sbtv')
}, err => {
if (err) throw err
console.log('Done')
})
//As a Promise:
util.promisify(sb.writeTypeAndValue)({
type: new sb.FlexUnsignedIntType,
value: 1000,
outStream: fs.createWriteStream('out.sbtv')
})
.then(_ => console.log('Done'))
The type of value being written
The optional callback to call when write ends
outStream
Writes the contents of type.valueBuffer(value)
(Type.valueBuffer)
to a writable stream and then closes the stream.
Calls callback
when done.
Example:
//With a callback:
sb.writeValue({
type: new sb.FlexUnsignedIntType,
value: 1000,
outStream: fs.createWriteStream('out.sbv')
}, err => {
if (err) throw err
console.log('Done')
})
//As a Promise:
util.promisify(sb.writeValue)({
type: new sb.FlexUnsignedIntType,
value: 1000,
outStream: fs.createWriteStream('out.sbv')
})
.then(_ => console.log('Done'))
The type of value being written
The optional callback to call when write ends
outStream
Generated using TypeDoc
A callback that receives only a possible error