-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
1,100 additions
and
1,187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export enum MessagePriority { | ||
Normal = 'normal', | ||
High = 'high', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const _bufferToString = (buffer: Uint8Array): ReadableStream<Uint8Array> => { | ||
return new ReadableStream({ | ||
start(controller) { | ||
controller.enqueue(buffer); | ||
controller.close(); | ||
} | ||
}); | ||
}; | ||
|
||
export class InputFile { | ||
stream: ReadableStream<Uint8Array>; // Content of file as a stream | ||
size: number; // Total final size of the file content | ||
filename: string; // File name | ||
|
||
static fromPath = (filePath: string, filename: string): InputFile => { | ||
const file = Deno.openSync(filePath); | ||
const stream = file.readable; | ||
const size = Deno.statSync(filePath).size; | ||
return new InputFile(stream, filename, size); | ||
}; | ||
|
||
static fromBlob = async (blob: Blob, filename: string) => { | ||
const arrayBuffer = await blob.arrayBuffer(); | ||
const buffer = new Uint8Array(arrayBuffer); | ||
return InputFile.fromBuffer(buffer, filename); | ||
}; | ||
|
||
static fromBuffer = (buffer: Uint8Array, filename: string): InputFile => { | ||
const stream = _bufferToString(buffer); | ||
const size = buffer.byteLength; | ||
return new InputFile(stream, filename, size); | ||
}; | ||
|
||
static fromPlainText = (content: string, filename: string): InputFile => { | ||
const buffer = new TextEncoder().encode(content); | ||
const stream = _bufferToString(buffer); | ||
const size = buffer.byteLength; | ||
return new InputFile(stream, filename, size); | ||
}; | ||
|
||
constructor(stream: ReadableStream<Uint8Array>, filename: string, size: number) { | ||
this.stream = stream; | ||
this.filename = filename; | ||
this.size = size; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.