fix(now handles binary files): update
This commit is contained in:
19
ts/index.ts
19
ts/index.ts
@ -3,9 +3,9 @@ import * as https from 'https';
|
||||
import * as plugins from './smartrequest.plugins';
|
||||
import * as interfaces from './smartrequest.interfaces';
|
||||
|
||||
import { request } from './smartrequest.request';
|
||||
import { request, extendedIncomingMessage } from './smartrequest.request';
|
||||
|
||||
export { request } from './smartrequest.request';
|
||||
export { request, extendedIncomingMessage } from './smartrequest.request';
|
||||
export { ISmartRequestOptions } from './smartrequest.interfaces';
|
||||
|
||||
export let get = async (domainArg: string, optionsArg: interfaces.ISmartRequestOptions = {}) => {
|
||||
@ -14,6 +14,21 @@ export let get = async (domainArg: string, optionsArg: interfaces.ISmartRequestO
|
||||
return response;
|
||||
};
|
||||
|
||||
export let getBinary = async (domainArg: string, optionsArg: interfaces.ISmartRequestOptions = {}) => {
|
||||
const response = await request(domainArg, optionsArg, true);
|
||||
var data = [];
|
||||
|
||||
response.on('data', function(chunk) {
|
||||
data.push(chunk);
|
||||
}).on('end', function() {
|
||||
//at this point data is an array of Buffers
|
||||
//so Buffer.concat() can make us a new Buffer
|
||||
//of all of them together
|
||||
const buffer = Buffer.concat(data);
|
||||
response.body = buffer.toString('base64');
|
||||
});
|
||||
}
|
||||
|
||||
export let post = async (domainArg: string, optionsArg: interfaces.ISmartRequestOptions = {}) => {
|
||||
optionsArg.method = 'POST';
|
||||
if (
|
||||
|
@ -31,7 +31,7 @@ export let request = async (
|
||||
domainArg: string,
|
||||
optionsArg: interfaces.ISmartRequestOptions = {},
|
||||
streamArg: boolean = false
|
||||
): Promise<Response> => {
|
||||
): Promise<extendedIncomingMessage> => {
|
||||
let done = plugins.q.defer<any>();
|
||||
let parsedUrl: plugins.url.Url;
|
||||
if (domainArg) {
|
||||
|
Reference in New Issue
Block a user