Always use diskdown 32-byte keys

This commit is contained in:
Jaco Greeff
2018-08-27 16:35:21 +02:00
parent 44ce7fa901
commit e42a70fb1b
+15
View File
@@ -13,6 +13,7 @@ import Combined from './store/Combined';
// import Scatter from './store/Scatter';
const LRU_SIZE = 8192;
const KEY_LENGTH = 32;
const l = logger('disk/scatter');
const noop = () =>
@@ -85,6 +86,20 @@ class DiskDown extends AbstractLevelDOWN {
process.nextTick(callback);
}
_serializeKey (key: Buffer): Buffer {
if (key.length === KEY_LENGTH) {
return key;
} else if (key.length < KEY_LENGTH) {
const paddedKey = Buffer.alloc(KEY_LENGTH);
paddedKey.set(key, 0);
return paddedKey;
}
throw new Error(`${key.toString()} too large, expected <= 32 bytes`);
}
}
export default function (location: string) {