Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/typescript conversion/27 #33

Merged
merged 7 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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
34 changes: 29 additions & 5 deletions lib/bufferReader.js → lib/bufferReader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
module.exports = class BufferReader {
constructor(envelopeReader, options) {
interface BufferReaderOptions {
maxSpan?: number,
maxLength?: number,
queueWait?: number
}

interface BufferReaderQueueRow {
offset: number,
length: number,
resolve: (buf: Buffer) => void
reject: unknown
}

interface EnvelopeReader {
readFn: (start: number, finish: number) => Promise<Buffer>
}

export default class BufferReader {
maxSpan: number
maxLength: number
queueWait: number
scheduled?: boolean
queue: Array<BufferReaderQueueRow>
envelopeReader: EnvelopeReader

constructor(envelopeReader: EnvelopeReader, options: BufferReaderOptions) {
options = options || {};
this.envelopeReader = envelopeReader;
this.maxSpan = options.maxSpan || 100000; // 100k
Expand All @@ -9,7 +33,7 @@ module.exports = class BufferReader {
this.queue = [];
}

async read(offset, length) {
async read(offset: number, length: number) {
if (!this.scheduled) {
this.scheduled = true;
setTimeout( () => {
Expand All @@ -29,7 +53,7 @@ module.exports = class BufferReader {
this.queue = [];
queue.sort( (a,b) => a.offset - b.offset);

var subqueue = [];
var subqueue: Array<BufferReaderQueueRow> = [];

const readSubqueue = async () => {
if (!subqueue.length) {
Expand Down Expand Up @@ -61,6 +85,6 @@ module.exports = class BufferReader {
subqueue = [d];
}
});
readSubqueue(subqueue);
readSubqueue();
}
};
4 changes: 0 additions & 4 deletions lib/codec/index.js

This file was deleted.

5 changes: 5 additions & 0 deletions lib/codec/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * as PLAIN from './plain'
export * as RLE from './rle'
export * as PLAIN_DICTIONARY from './plain_dictionary'


275 changes: 0 additions & 275 deletions lib/codec/plain.js

This file was deleted.

Loading