Random Access Network
A Random Access Storage implementation that goes through a Transport.
Installation
npm install random-access-network --save
Usage
const RAN StreamTransport = const stream = const storage = storage
Advanced example with a WebSocket transport:
const WebSocket = const RAN = // see belowconst WssTransport = const sock = 'ws://localhost:8080'const transport = 'test' sockconst file = sock
Random access network bridge
random-access-network
provides a bridge utility to transform a request to a random-access-storage
call:
const raf = const RasBridge = const ras =
Usage example in the websocket case:
const WebSocket = const raf = const RasBridge = const ras = const wss = port: 8080 wss
Transport
A transport is a class that sends/receive data to/from an interface (network, IPC etc.) and handles encoding/decoding.
The NoopTransport
handles the correct propagation of request/callbacks. When creating your own transport you should implement the methods send
, onmessage
and optionally close
:
send
gets a buffer to be send to the network of your choiceonmessage
should callthis._next(buffer)
once you've transformed the received data in a bufferclose
if you want to close the network interface
For example a websocket transport:
const NoopTransport = { NoopTransport this_sock = socket this_sock} WssTransportprototype = Object WssTransportprototype { this_sock} WssTransportprototype { this} WssTransportprototype { this_sock}
If you're using a duplex stream you can use the provided StreamTransport:
const StreamTransport =
See also the native messaging implementation.