diff --git a/lib/persistence.js b/lib/persistence.js index 4839693..538e523 100755 --- a/lib/persistence.js +++ b/lib/persistence.js @@ -156,7 +156,6 @@ class Persistence { treatRawData (rawData) { const data = rawData.split('\n') const dataById = {} - const tdata = [] const indexes = {} // Last line of every data file is usually blank so not really corrupt @@ -181,7 +180,7 @@ class Persistence { corruptItems / data.length > this.corruptAlertThreshold ) throw new Error(`More than ${Math.floor(100 * this.corruptAlertThreshold)}% of the data file is corrupt, the wrong beforeDeserialization hook may be used. Cautiously refusing to start NeDB to prevent dataloss`) - tdata.push(...Object.values(dataById)) + const tdata = Object.values(dataById) return { data: tdata, indexes: indexes } } @@ -192,7 +191,6 @@ class Persistence { */ treatRawStream (rawStream, cb) { const dataById = {} - const tdata = [] const indexes = {} // Last line of every data file is usually blank so not really corrupt @@ -224,11 +222,9 @@ class Persistence { return } - Object.keys(dataById).forEach(function (k) { - tdata.push(dataById[k]) - }) + const data = Object.values(dataById) - cb(null, { data: tdata, indexes: indexes }) + cb(null, { data, indexes: indexes }) }) lineStream.on('error', function (err) { diff --git a/test/persistence.test.js b/test/persistence.test.js index ec35f02..5fa46e1 100755 --- a/test/persistence.test.js +++ b/test/persistence.test.js @@ -282,7 +282,7 @@ describe('Persistence', function () { const treatedData = result.data const indexes = result.indexes Object.keys(indexes).length.should.equal(1) - assert.deepEqual(indexes.test, { fieldName: 'test', unique: true }) + assert.deepStrictEqual(indexes.test, { fieldName: 'test', unique: true }) treatedData.sort(function (a, b) { return a._id - b._id }) treatedData.length.should.equal(2)