Options
All
  • Public
  • Public/Protected
  • All
Menu

Module io

Index

Type aliases

ErrCallback

ErrCallback: (err: Error | null) => void

A callback that receives only a possible error

Type declaration

    • (err: Error | null): void
    • Parameters

      • err: Error | null

      Returns void

TypeAndValueCallback

TypeAndValueCallback<E>: (err: Error | null, type: Type<E>, value: E) => void

A callback that receives a possible error and, if no error occurred, a read type and value

Type parameters

  • E

Type declaration

    • (err: Error | null, type: Type<E>, value: E): void
    • Parameters

      • err: Error | null
      • type: Type<E>
      • value: E

      Returns void

TypeCallback

TypeCallback<E>: (err: Error | null, type: Type<E>) => void

A callback that receives a possible error and, if no error occurred, a read type

Type parameters

  • E

Type declaration

    • (err: Error | null, type: Type<E>): void
    • Parameters

      • err: Error | null
      • type: Type<E>

      Returns void

ValueCallback

ValueCallback<E>: (err: Error | null, value: E) => void

A callback that receives a possible error and, if no error occurred, a read value

Type parameters

  • E

Type declaration

    • (err: Error | null, value: E): void
    • Parameters

      • err: Error | null
      • value: E

      Returns void

Variables

Const readTypeAndValue

readTypeAndValue: <E>(inStream: Readable, callback: TypeAndValueCallback<E>) => void & CustomPromisifySymbol<<E>(inStream: Readable) => Promise<TypeAndValue<E>>> = ...

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))
param

The stream to read from

param

The callback to call with the read result

Functions

httpRespond

  • 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
    })
    

    Type parameters

    • E

    Parameters

    • __namedParameters: HttpParams<E>
    • Optional callback: ErrCallback

      The optional callback to call when response ends

    Returns void

readType

  • readType<E>(inStream: Readable, callback: TypeCallback<E>): void
  • 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))
    

    Type parameters

    • E

    Parameters

    • inStream: Readable

      The stream to read from

    • callback: TypeCallback<E>

      The callback to call with the read result

    Returns void

readValue

  • 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))
    

    Type parameters

    • E

      The type of value being read (must match the VALUE parameter of type)

    Parameters

    Returns void

writeType

  • 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'))
    

    Parameters

    • __namedParameters: WriteParams<unknown>
    • Optional callback: ErrCallback

      The optional callback to call when write ends

    Returns Writable

    outStream

writeTypeAndValue

  • 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'))
    

    Type parameters

    • E

      The type of value being written

    Parameters

    Returns Writable

    outStream

writeValue

  • 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'))
    

    Type parameters

    • E

      The type of value being written

    Parameters

    Returns Writable

    outStream

Generated using TypeDoc