Skip to content

Commit a97e95c

Browse files
committed
Reduced compiled size by removing AppendableStream
1 parent 03c2403 commit a97e95c

16 files changed

+57
-49
lines changed

compiled/download.js

Lines changed: 1 addition & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiled/upload-download.js

Lines changed: 1 addition & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiled/upload.js

Lines changed: 1 addition & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/lib/appendable-stream.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import AppendableBuffer from './appendable';
88
* by calling [[end]] after all bytes
99
* have been written.
1010
*/
11-
export default class AppendableStream implements AppendableBuffer {
11+
export default class AppendableStream extends AppendableBuffer {
1212
private readonly outStream;
1313
private writtenBytes;
1414
private pauseCount;

dist/lib/appendable-stream.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Object.defineProperty(exports, "__esModule", { value: true });
33
const http_1 = require("http");
44
const stream_1 = require("stream");
5+
const appendable_1 = require("./appendable");
56
const assert_1 = require("./assert");
67
const growable_buffer_1 = require("./growable-buffer");
78
const WRITABLE_STREAMS = [stream_1.Writable, stream_1.Duplex, http_1.OutgoingMessage];
@@ -12,11 +13,12 @@ const WRITABLE_STREAMS = [stream_1.Writable, stream_1.Duplex, http_1.OutgoingMes
1213
* by calling [[end]] after all bytes
1314
* have been written.
1415
*/
15-
class AppendableStream {
16+
class AppendableStream extends appendable_1.default {
1617
/**
1718
* @param outStream The underlying writable stream
1819
*/
1920
constructor(outStream) {
21+
super();
2022
assert_1.default.instanceOf(outStream, WRITABLE_STREAMS);
2123
this.outStream = outStream;
2224
this.writtenBytes = 0;

dist/lib/appendable.d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,25 @@
1616
* console.log(new Uint8Array(gb.toBuffer())) //Uint8Array [ 1, 2, 3, 4, 5 ]
1717
* ````
1818
*/
19-
export default interface AppendableBuffer {
19+
export default abstract class AppendableBuffer {
2020
/**
2121
* The number of bytes that have been written
2222
*/
23-
readonly length: number;
23+
readonly abstract length: number;
2424
/**
2525
* Adds a byte after the end
2626
* of the written data
2727
* @param value The unsigned byte value to add
2828
*/
29-
add(value: number): this;
29+
abstract add(value: number): this;
3030
/**
3131
* Adds a contiguous set of bytes
3232
* after the end of the written data
3333
* @param buffer The bytes to add.
3434
* The byte at position `i` in `buffer` will be written to
3535
* position `this.length + i`.
3636
*/
37-
addAll(buffer: ArrayBuffer): this;
37+
abstract addAll(buffer: ArrayBuffer): this;
3838
/**
3939
* Pauses the writing process, i.e.
4040
* bytes added are not written
@@ -59,14 +59,14 @@ export default interface AppendableBuffer {
5959
* console.log(new Uint8Array(gb.toBuffer())) //Uint8Array [ 1, 2, 3 ]
6060
* ````
6161
*/
62-
pause(): this;
62+
abstract pause(): this;
6363
/**
6464
* See [[pause]].
6565
* Flushes all paused data to the output
6666
* and exits paused mode.
6767
* @throws If not currently paused
6868
*/
69-
resume(): this;
69+
abstract resume(): this;
7070
/**
7171
* See [[pause]].
7272
* Restores state to immediately after
@@ -75,5 +75,5 @@ export default interface AppendableBuffer {
7575
* being flushed to the output.
7676
* @throws If not currently paused
7777
*/
78-
reset(): this;
78+
abstract reset(): this;
7979
}

dist/lib/appendable.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,23 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3+
/**
4+
* A "writable" interface, sufficient
5+
* to be able to write type and value bytes.
6+
* Implemented by [[GrowableBuffer]], as well as
7+
* [[AppendableStream]] (a wrapper around a writable stream).
8+
* All methods can be chained, e.g.
9+
* ````javascript
10+
* let gb = new GrowableBuffer
11+
* gb
12+
* .add(1).add(2)
13+
* .addAll(new Uint8Array([3, 4, 5]).buffer)
14+
* .pause()
15+
* .add(0)
16+
* .reset()
17+
* .resume()
18+
* console.log(new Uint8Array(gb.toBuffer())) //Uint8Array [ 1, 2, 3, 4, 5 ]
19+
* ````
20+
*/
21+
class AppendableBuffer {
22+
}
23+
exports.default = AppendableBuffer;

dist/lib/growable-buffer.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import AppendableBuffer from './appendable';
66
* Used extensively throughout the project for building up buffers.
77
* See [[GrowableBuffer.grow]] for an explanation of the growing process.
88
*/
9-
export default class GrowableBuffer implements AppendableBuffer {
9+
export default class GrowableBuffer extends AppendableBuffer {
1010
private buffer;
1111
private size;
1212
private readonly pausePoints;

dist/lib/growable-buffer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3+
const appendable_1 = require("./appendable");
34
const assert_1 = require("./assert");
45
const INITIAL_LENGTH = 10;
56
/**
@@ -9,13 +10,14 @@ const INITIAL_LENGTH = 10;
910
* Used extensively throughout the project for building up buffers.
1011
* See [[GrowableBuffer.grow]] for an explanation of the growing process.
1112
*/
12-
class GrowableBuffer {
13+
class GrowableBuffer extends appendable_1.default {
1314
/**
1415
* @param initialLength
1516
* The number of bytes in the internal buffer at start
1617
* (defaults to 10)
1718
*/
1819
constructor(initialLength = INITIAL_LENGTH) {
20+
super();
1921
try {
2022
assert_1.default.integer(initialLength);
2123
assert_1.default(initialLength >= 0);

dist/types/abstract.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
33
const base64 = require("base64-js");
44
const sha_256_1 = require("../lib/sha-256");
55
const config_1 = require("../config");
6-
const appendable_stream_1 = require("../lib/appendable-stream");
6+
const appendable_1 = require("../lib/appendable");
77
const assert_1 = require("../lib/assert");
88
const constants_1 = require("../lib/constants");
99
const flexInt = require("../lib/flex-int");
1010
const growable_buffer_1 = require("../lib/growable-buffer");
1111
const recursiveNesting = require("../lib/recursive-nesting");
12-
const APPENDABLES = [growable_buffer_1.default, appendable_stream_1.default];
1312
/**
1413
* The superclass of all [[Type]] classes
1514
* in this package
@@ -94,7 +93,7 @@ class AbstractType {
9493
* @param buffer The value to assert is an [[AppendableBuffer]]
9594
*/
9695
isBuffer(buffer) {
97-
assert_1.default.instanceOf(buffer, APPENDABLES);
96+
assert_1.default.instanceOf(buffer, appendable_1.default);
9897
}
9998
/**
10099
* Generates the type buffer, recomputed each time

0 commit comments

Comments
 (0)