Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Type definitions for msgpack 2.0.0
// Project: https://github.com/enochgroot/msgpack-node

/// <reference types="node" />

import { EventEmitter } from 'events';

/**
* Serialize values to MessagePack.
*
* A single argument is packed as itself; two or more are packed as an array
* of that many elements.
*/
export function pack(...values: any[]): Buffer;

/**
* Deserialize the first MessagePack value in `buf`.
*
* Returns `null` when the buffer holds an incomplete value, in which case
* `unpack.bytes_remaining` equals `buf.length`. Throws on malformed input or
* when a container/string/bin header exceeds the decoder's limits.
*/
export function unpack(buf: Buffer): any;

export namespace unpack {
/**
* Bytes left in the buffer passed to the most recent `unpack()` call on
* this thread. Read it immediately after `unpack()`: the next call
* overwrites it.
*/
let bytes_remaining: number;
}

/**
* Frames MessagePack messages over a stream.
*
* Emits `'msg'` with each decoded value, and `'error'` if a packet cannot be
* decoded (the buffered data is then dropped).
*/
export class Stream extends EventEmitter {
constructor(s: NodeJS.ReadWriteStream);

/** Buffered bytes not yet forming a complete message, or `null`. */
buf: Buffer | null;

/**
* Pack `m` and write it to the underlying stream. Extra arguments are
* forwarded to `stream.write()` (encoding, callback).
*/
send(m: any, ...args: any[]): boolean;
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"url": "https://github.com/enochgroot/msgpack-node.git"
},
"main": "./lib/msgpack",
"types": "index.d.ts",
"directories": {
"lib": "lib"
},
Expand Down
Loading