Last active
October 10, 2019 11:17
-
-
Save loderunner/4c24ab4f7684f1b180c148a01de35f63 to your computer and use it in GitHub Desktop.
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
interface Reader { | |
read(): Promise<Buffer>; | |
} | |
class FileReader implements Reader { | |
private path: string; | |
constructor(path: string) { | |
this.path = path; | |
} | |
async read() { | |
return fs.readFileSync(path); | |
} | |
} | |
class URLReader implements Reader { | |
private url: string; | |
constructor(url: string) { | |
this.url = url; | |
} | |
async read() { | |
return new Promise((resolve, reject) => { | |
http.get(this.url, res => { | |
// stream data from response and resolve Promise | |
}); | |
} | |
} | |
} |
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
interface Renamable { | |
name: string | |
modificationDate: Date; | |
} | |
function rename(r: Renamable, name: string) { | |
r.name = name; | |
r.modificationDate = new Date(); | |
} | |
class File implements Renamable { | |
name: string; | |
creationDate: Date; | |
modificationDate: Date; | |
contents: Buffer; | |
} | |
class Bucket implements Renamable { | |
name: string; | |
creationDate: Date; | |
modificationDate: Date; | |
files: File[] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment