-
Notifications
You must be signed in to change notification settings - Fork 41
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
21 changed files
with
412 additions
and
337 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import type { Payload } from './payload'; | ||
|
||
/** | ||
* Appwrite Models | ||
*/ | ||
|
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,43 @@ | ||
export class Payload { | ||
private data: Buffer; | ||
public filename?: string; | ||
public size: number; | ||
|
||
constructor(data: Buffer, filename?: string) { | ||
this.data = data; | ||
this.filename = filename; | ||
this.size = data.byteLength; | ||
} | ||
|
||
public toBinary(offset: number = 0, length?: number): Buffer { | ||
if (offset === 0 && length === undefined) { | ||
return this.data; | ||
} else if (length === undefined) { | ||
return this.data.subarray(offset); | ||
} else { | ||
return this.data.subarray(offset, offset + length); | ||
} | ||
} | ||
|
||
public toJson<T = unknown>(): T { | ||
return JSON.parse(this.toString()); | ||
} | ||
|
||
public toString(): string { | ||
return this.data.toString("utf-8"); | ||
} | ||
|
||
public static fromBinary(bytes: Buffer, filename?: string): Payload { | ||
return new Payload(bytes, filename); | ||
} | ||
|
||
public static fromJson(object: any, filename?: string): Payload { | ||
const data = Buffer.from(JSON.stringify(object), "utf-8"); | ||
return new Payload(data, filename); | ||
} | ||
|
||
public static fromString(text: string, filename?: string): Payload { | ||
const data = Buffer.from(text, "utf-8"); | ||
return new Payload(data, filename); | ||
} | ||
} |
Oops, something went wrong.