| 2951 | } |
| 2952 | |
| 2953 | class Uint8ArrayWriter extends Writer { |
| 2954 | |
| 2955 | constructor(defaultBufferSize) { |
| 2956 | super(); |
| 2957 | this.defaultBufferSize = defaultBufferSize || DEFAULT_BUFFER_SIZE; |
| 2958 | } |
| 2959 | |
| 2960 | init(initSize = 0) { |
| 2961 | Object.assign(this, { |
| 2962 | offset: 0, |
| 2963 | array: new Uint8Array(initSize > 0 ? initSize : this.defaultBufferSize) |
| 2964 | }); |
| 2965 | super.init(); |
| 2966 | } |
| 2967 | |
| 2968 | writeUint8Array(array) { |
| 2969 | const writer = this; |
| 2970 | const requiredLength = writer.offset + array.length; |
| 2971 | if (requiredLength > writer.array.length) { |
| 2972 | let newLength = writer.array.length ? writer.array.length * 2 : writer.defaultBufferSize; |
| 2973 | while (newLength < requiredLength) { |
| 2974 | newLength *= 2; |
| 2975 | } |
| 2976 | const previousArray = writer.array; |
| 2977 | writer.array = new Uint8Array(newLength); |
| 2978 | writer.array.set(previousArray); |
| 2979 | } |
| 2980 | writer.array.set(array, writer.offset); |
| 2981 | writer.offset += array.length; |
| 2982 | } |
| 2983 | |
| 2984 | getData() { |
| 2985 | if (this.offset === this.array.length) { |
| 2986 | return this.array; |
| 2987 | } else { |
| 2988 | return this.array.slice(0, this.offset); |
| 2989 | } |
| 2990 | } |
| 2991 | } |
| 2992 | |
| 2993 | class SplitDataReader extends Reader { |
| 2994 |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…