-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
45119e8
commit 84115ef
Showing
12 changed files
with
328 additions
and
227 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import * as fs from 'fs'; | ||
import {ServerResponse} from 'https'; | ||
import * as zlib from 'zlib'; | ||
|
||
import {ColorConsole} from './console'; | ||
|
||
export class Helpers { | ||
static readFile(filename: string): string { | ||
try { | ||
return fs.readFileSync(filename).toString(); | ||
} catch (e) { | ||
const console = new ColorConsole(); | ||
console.error('`' + filename + '` missing or inaccesible'); | ||
console.error(e); | ||
return undefined; | ||
} | ||
} | ||
|
||
static watchFile(filename: string, listener: FunctionStringCallback): void { | ||
console.log('watching: ' + filename); | ||
fs.watch(filename, () => { | ||
const result = this.readFile(filename); | ||
if (result) { | ||
listener(result); | ||
} | ||
}); | ||
} | ||
|
||
static jsonParse(data: string): any { | ||
let json = data; | ||
try { | ||
json = JSON.parse(data); | ||
} catch (e) { | ||
console.log('json parse failed: ' + e); | ||
} | ||
return json; | ||
} | ||
|
||
static jsonStringify(json: any): string { | ||
let data = json; | ||
try { | ||
data = JSON.stringify(json); | ||
} catch (e) { | ||
console.log('json stringify failed: ' + e); | ||
} | ||
return data; | ||
} | ||
|
||
static gzip(data: any): Buffer { | ||
return zlib.gzipSync(data); | ||
} | ||
|
||
static jsonGzip(data: any): Buffer { | ||
return this.gzip(this.jsonStringify(data)); | ||
} | ||
} |
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.