aboutsummaryrefslogtreecommitdiff
path: root/node_modules/to-buffer/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/to-buffer/index.js')
-rw-r--r--node_modules/to-buffer/index.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/node_modules/to-buffer/index.js b/node_modules/to-buffer/index.js
new file mode 100644
index 0000000..9bd4978
--- /dev/null
+++ b/node_modules/to-buffer/index.js
@@ -0,0 +1,14 @@
+module.exports = toBuffer
+
+var makeBuffer = Buffer.from && Buffer.from !== Uint8Array.from ? Buffer.from : bufferFrom
+
+function bufferFrom (buf, enc) {
+ return new Buffer(buf, enc)
+}
+
+function toBuffer (buf, enc) {
+ if (Buffer.isBuffer(buf)) return buf
+ if (typeof buf === 'string') return makeBuffer(buf, enc)
+ if (Array.isArray(buf)) return makeBuffer(buf)
+ throw new Error('Input should be a buffer or a string')
+}