1.0.6 • Published 5 months ago

bfj-collections v1.0.6

Weekly downloads
15
License
MIT
Repository
github
Last release
5 months ago

bfj-collections

A simple addon to the excellent bfj module which provides a simple parser for very large JSON files in the form of collections.

Assumptions:

  • Your JSON input is huge (otherwise you would just read it in via JSON.parse)
  • Your data is in the form of a collection (i.e. an array of objects)
  • You can hold each individual object in that collection in memory but not the whole input data

Why

While BFJ is excellent at working with very large JSON files sometimes you just want to be able to read all items in a collection without having to do the parsing yourself.

Example

The below example demonstrates how to read in a very large JSON file and emits bfjc every time we can parse an object within the collection:

bfjc(fs.createReadStream('someBigFile.json'))
	.on('bfjc', data => ... do something with the object entity ...)
	.on(bfj.events.end, ()=> ... we have finished reading ...)

API

bfjc(stream, options)

The main exported function functions exactly the same as bfj.walk and takes exactly the same input stream and options. See that functions documentation for more details.

Additional options are listed below:

OptionTypeDefaultDescription
pausebooleantrueInstruct the stream to pause before each bfjc emit event
allowArraysbooleanfalseAllow nested array objects e.g. [['One'], [['Two']]]
allowScalarsbooleanfalseAllow scalar types (strings, numebers, booleans) as object types

NOTES:

  • The pause functionality assumes the events are syncronous not asyncronous. If you wish to wrap pausing in promises or other event driven functionality you will have to add your own code after disabling pause
1.0.6

5 months ago

1.0.5

4 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

6 years ago

1.0.0

6 years ago