diff --git a/lib.es5/node/base64.js b/lib.es5/node/base64.js index 59776c39..dc78d960 100644 --- a/lib.es5/node/base64.js +++ b/lib.es5/node/base64.js @@ -4,11 +4,17 @@ Object.defineProperty(exports, "__esModule", { value: true }); +exports.isSupported = undefined; exports.encode = encode; -/* global: Buffer */ + +var _bufferFrom = require("buffer-from"); + +var _bufferFrom2 = _interopRequireDefault(_bufferFrom); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function encode(data) { - return new Buffer(data).toString("base64"); + return (0, _bufferFrom2.default)(String(data)).toString("base64"); } var isSupported = exports.isSupported = true; \ No newline at end of file diff --git a/lib/node/base64.js b/lib/node/base64.js index 30d21414..5003cf20 100644 --- a/lib/node/base64.js +++ b/lib/node/base64.js @@ -1,7 +1,7 @@ -/* global: Buffer */ +import bufferFrom from "buffer-from"; export function encode(data) { - return new Buffer(data).toString("base64"); + return bufferFrom(String(data)).toString("base64"); } export const isSupported = true; diff --git a/package.json b/package.json index 633f9adc..acab73a7 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "watchify": "^3.5.0" }, "dependencies": { + "buffer-from": "^0.1.1", "extend": "^3.0.0", "lodash.throttle": "^4.1.1", "resolve-url": "^0.2.1" diff --git a/test/spec/upload.js b/test/spec/upload.js index a905c034..87d9ceab 100644 --- a/test/spec/upload.js +++ b/test/spec/upload.js @@ -35,7 +35,8 @@ describe("tus", function () { metadata: { foo: "hello", bar: "world", - nonlatin: "słońce" + nonlatin: "słońce", + number: 100 }, withCredentials: true, onProgress: function () {}, @@ -57,7 +58,7 @@ describe("tus", function () { expect(req.requestHeaders["Upload-Length"]).toBe(11); if (isBrowser) expect(req.withCredentials).toBe(true); if (isNode || (isBrowser && "btoa" in window)) { - expect(req.requestHeaders["Upload-Metadata"]).toBe("foo aGVsbG8=,bar d29ybGQ=,nonlatin c8WCb8WEY2U="); + expect(req.requestHeaders["Upload-Metadata"]).toBe("foo aGVsbG8=,bar d29ybGQ=,nonlatin c8WCb8WEY2U=,number MTAw"); } req.respondWith({