32 lines
4.1 KiB
JavaScript
32 lines
4.1 KiB
JavaScript
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.stringifyHeaderValues = exports.fromBase64String = exports.toBase64String = exports.getResponseAsBuffer = exports.getResponseAsString = void 0;
|
||
|
function getResponseAsString(response) {
|
||
|
return response.base64Encoded
|
||
|
? Buffer.from(response.body, 'base64').toString()
|
||
|
: response.body;
|
||
|
}
|
||
|
exports.getResponseAsString = getResponseAsString;
|
||
|
function getResponseAsBuffer(response) {
|
||
|
return response.base64Encoded
|
||
|
? Buffer.from(response.body, 'base64')
|
||
|
: Buffer.from(response.body);
|
||
|
}
|
||
|
exports.getResponseAsBuffer = getResponseAsBuffer;
|
||
|
function toBase64String(str) {
|
||
|
return Buffer.from(str).toString('base64');
|
||
|
}
|
||
|
exports.toBase64String = toBase64String;
|
||
|
function fromBase64String(str) {
|
||
|
return Buffer.from(str, 'base64');
|
||
|
}
|
||
|
exports.fromBase64String = fromBase64String;
|
||
|
function stringifyHeaderValues(headers) {
|
||
|
return headers.map(({ name, value }) => {
|
||
|
if (typeof value !== 'string')
|
||
|
value = value.toString ? value.toString() : String(value);
|
||
|
return { name, value };
|
||
|
});
|
||
|
}
|
||
|
exports.stringifyHeaderValues = stringifyHeaderValues;
|
||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RyaW5nLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3Byb3h5bGVzcy91dGlscy9zdHJpbmcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBSUEsU0FBZ0IsbUJBQW1CLENBQUUsUUFBaUM7SUFDbEUsT0FBTyxRQUFRLENBQUMsYUFBYTtRQUN6QixDQUFDLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxRQUFRLENBQUMsSUFBSSxFQUFFLFFBQVEsQ0FBQyxDQUFDLFFBQVEs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