pw-buffer 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![npm version](https://badge.fury.io/js/pw-buffer.svg)](https://badge.fury.io/js/pw-buffer)
2
+
1
3
  # Perfect World binary utils
2
4
 
3
5
  A small TypeScript/Node.js library built on top of [extended-buffer](https://github.com/mvcbox/node-extended-buffer) that adds helpers commonly found in some Perfect World / PW-style binary protocols:
@@ -4,5 +4,5 @@ import { Transform, TransformOptions } from 'stream';
4
4
  export declare class MppcCompressorTransform extends Transform {
5
5
  protected readonly _mppcCompressor: MppcCompressor;
6
6
  constructor(transformOptions?: TransformOptions);
7
- _transform(chunk: Buffer | null, encoding: string, callback: Function): void;
7
+ _transform(chunk: Buffer, encoding: string, callback: Function): void;
8
8
  }
@@ -2,14 +2,27 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MppcCompressorTransform = void 0;
4
4
  const mppc_1 = require("./mppc");
5
+ const errors_1 = require("./errors");
5
6
  const stream_1 = require("stream");
6
7
  class MppcCompressorTransform extends stream_1.Transform {
7
8
  constructor(transformOptions) {
8
- super(transformOptions);
9
+ super(Object.assign({
10
+ decodeStrings: true
11
+ }, transformOptions !== null && transformOptions !== void 0 ? transformOptions : {}));
9
12
  this._mppcCompressor = new mppc_1.MppcCompressor();
10
13
  }
11
14
  _transform(chunk, encoding, callback) {
12
- callback(null, chunk ? this._mppcCompressor.update(chunk) : null);
15
+ try {
16
+ if (chunk instanceof Buffer) {
17
+ callback(null, this._mppcCompressor.update(chunk));
18
+ }
19
+ else {
20
+ callback(new errors_1.PwBufferTypeError('INVALID_CHUNK_TYPE'));
21
+ }
22
+ }
23
+ catch (e) {
24
+ callback(e);
25
+ }
13
26
  }
14
27
  }
15
28
  exports.MppcCompressorTransform = MppcCompressorTransform;
@@ -4,5 +4,5 @@ import { Transform, TransformOptions } from 'stream';
4
4
  export declare class MppcDecompressorTransform extends Transform {
5
5
  protected readonly _mppcDecompressor: MppcDecompressor;
6
6
  constructor(transformOptions?: TransformOptions);
7
- _transform(chunk: Buffer | null, encoding: string, callback: Function): void;
7
+ _transform(chunk: Buffer, encoding: string, callback: Function): void;
8
8
  }
@@ -2,14 +2,27 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MppcDecompressorTransform = void 0;
4
4
  const mppc_1 = require("./mppc");
5
+ const errors_1 = require("./errors");
5
6
  const stream_1 = require("stream");
6
7
  class MppcDecompressorTransform extends stream_1.Transform {
7
8
  constructor(transformOptions) {
8
- super(transformOptions);
9
+ super(Object.assign({
10
+ decodeStrings: true
11
+ }, transformOptions !== null && transformOptions !== void 0 ? transformOptions : {}));
9
12
  this._mppcDecompressor = new mppc_1.MppcDecompressor();
10
13
  }
11
14
  _transform(chunk, encoding, callback) {
12
- callback(null, chunk ? this._mppcDecompressor.update(chunk) : null);
15
+ try {
16
+ if (chunk instanceof Buffer) {
17
+ callback(null, this._mppcDecompressor.update(chunk));
18
+ }
19
+ else {
20
+ callback(new errors_1.PwBufferTypeError('INVALID_CHUNK_TYPE'));
21
+ }
22
+ }
23
+ catch (e) {
24
+ callback(e);
25
+ }
13
26
  }
14
27
  }
15
28
  exports.MppcDecompressorTransform = MppcDecompressorTransform;
@@ -0,0 +1,2 @@
1
+ export declare class PwBufferError extends Error {
2
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PwBufferError = void 0;
4
+ class PwBufferError extends Error {
5
+ }
6
+ exports.PwBufferError = PwBufferError;
@@ -0,0 +1,3 @@
1
+ import { PwBufferError } from './PwBufferError';
2
+ export declare class PwBufferTypeError extends PwBufferError {
3
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PwBufferTypeError = void 0;
4
+ const PwBufferError_1 = require("./PwBufferError");
5
+ class PwBufferTypeError extends PwBufferError_1.PwBufferError {
6
+ }
7
+ exports.PwBufferTypeError = PwBufferTypeError;
@@ -0,0 +1,2 @@
1
+ export { PwBufferError } from './PwBufferError';
2
+ export { PwBufferTypeError } from './PwBufferTypeError';
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PwBufferTypeError = exports.PwBufferError = void 0;
4
+ var PwBufferError_1 = require("./PwBufferError");
5
+ Object.defineProperty(exports, "PwBufferError", { enumerable: true, get: function () { return PwBufferError_1.PwBufferError; } });
6
+ var PwBufferTypeError_1 = require("./PwBufferTypeError");
7
+ Object.defineProperty(exports, "PwBufferTypeError", { enumerable: true, get: function () { return PwBufferTypeError_1.PwBufferTypeError; } });
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './utils';
2
+ export * from './errors';
2
3
  export { PwBuffer } from './PwBuffer';
3
4
  export type { PwBufferOptions } from './PwBufferOptions';
4
5
  export { MppcCompressor, MppcDecompressor } from './mppc';
package/dist/index.js CHANGED
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.MppcDecompressorTransform = exports.MppcCompressorTransform = exports.MppcDecompressor = exports.MppcCompressor = exports.PwBuffer = void 0;
18
18
  __exportStar(require("./utils"), exports);
19
+ __exportStar(require("./errors"), exports);
19
20
  var PwBuffer_1 = require("./PwBuffer");
20
21
  Object.defineProperty(exports, "PwBuffer", { enumerable: true, get: function () { return PwBuffer_1.PwBuffer; } });
21
22
  var mppc_1 = require("./mppc");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pw-buffer",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "PW Buffer, Perfect World, Beijing Perfect World",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",