Merge remote-tracking branch 'origin/stream-files-by-line' into stream-files-by-line

Timothée Rebours 3 years ago
commit dc59832895
  1. 10
      lib/persistence.js
  2. 2
      test/persistence.test.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) {

@ -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)

Loading…
Cancel
Save