From 24018d94fb583705cdf80aaf54a9c71220483289 Mon Sep 17 00:00:00 2001 From: Martin Heidegger Date: Fri, 4 Sep 2020 02:05:16 +0900 Subject: [PATCH] fix: Using Uint8Array instead of Buffer to test for empty input - Also covers Uint8Arrays - doesn't require EMPTY constant --- index.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/index.js b/index.js index 755de7d..846eca7 100644 --- a/index.js +++ b/index.js @@ -3,9 +3,6 @@ const { AbstractIterator } = require('abstract-leveldown') -const EMPTY = Buffer.alloc(0) - - module.exports = class HyperDown extends AbstractLevelDOWN { constructor (tree) { super() @@ -19,7 +16,7 @@ module.exports = class HyperDown extends AbstractLevelDOWN { else if (key === '') throw new Error('key cannot be an empty string') // Quick check that will pass for valid keys. else if (typeof key === 'string') return key - else if (Buffer.isBuffer(key) && EMPTY.equals(key)) throw new Error('key cannot be an empty Buffer') + else if (key instanceof Uint8Array && key.length === 0) throw new Error('key cannot be an empty Uint8Array') else if ((key instanceof Array) && key.length === 0) throw new Error('key cannot be an empty string') else if (typeof key === 'number' || typeof key === 'boolean') key = String(key) else if (Array.isArray(key)) key = key.join(',')