2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-08 17:22:34 +03:00

Allow ArrayBuffer and related views as data

In order to push binary data under the form of ArrayBuffer and
its related views (Int8Array, ...) one needs not to stringify
those.

For the XHR adapter there is nothing to do as it natively supports
ArrayBuffer in req.send().

Node's http adapter supports only string or Buffer thus a
transformation to Buffer is required before setting content length
header.
This commit is contained in:
Mathieu Bruyen
2014-09-18 09:07:08 +02:00
parent d8f687dc52
commit 095a204c5b
8 changed files with 124 additions and 9 deletions
+26
View File
@@ -12,6 +12,30 @@ function isArray(val) {
return toString.call(val) === '[object Array]';
}
/**
* Determine if a value is an ArrayBuffer
*
* @param {Object} val The value to test
* @returns {boolean} True if value is an ArrayBuffer, otherwise false
*/
function isArrayBuffer(val) {
return toString.call(val) === '[object ArrayBuffer]';
}
/**
* Determine if a value is a view on an ArrayBuffer
*
* @param {Object} val The value to test
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
*/
function isArrayBufferView(val) {
if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
return ArrayBuffer.isView(val);
} else {
return (val) && (val.buffer) && (val.buffer instanceof ArrayBuffer);
}
}
/**
* Determine if a value is a String
*
@@ -153,6 +177,8 @@ function merge(obj1/*, obj2, obj3, ...*/) {
module.exports = {
isArray: isArray,
isArrayBuffer: isArrayBuffer,
isArrayBufferView: isArrayBufferView,
isString: isString,
isNumber: isNumber,
isObject: isObject,