readme display

This commit is contained in:
Joao Moreno
2016-04-12 12:38:11 +02:00
parent fcdf38f0d7
commit e6d9e8d6d4
5 changed files with 88 additions and 21 deletions

View File

@@ -86,6 +86,23 @@ export function download(filePath: string, opts: IRequestOptions): TPromise<void
}));
}
export function text(opts: IRequestOptions): TPromise<string> {
return request(opts).then(pair => new Promise((c, e) => {
if (!((pair.res.statusCode >= 200 && pair.res.statusCode < 300) || pair.res.statusCode === 1223)) {
return e('Server returned ' + pair.res.statusCode);
}
if (pair.res.statusCode === 204) {
return c(null);
}
let buffer: string[] = [];
pair.res.on('data', d => buffer.push(d));
pair.res.on('end', () => c(buffer.join('')));
pair.res.on('error', e);
}));
}
export function json<T>(opts: IRequestOptions): TPromise<T> {
return request(opts).then(pair => new Promise((c, e) => {
if (!((pair.res.statusCode >= 200 && pair.res.statusCode < 300) || pair.res.statusCode === 1223)) {