-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
32 lines (26 loc) · 1.1 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
var Blocks = require('aligned-block-file')
var createFrame = require('./frame/recoverable')
var Cache = require('hashlru')
var inject = require('./inject')
function id (e) { return e }
function isNumber(n) { return 'number' == typeof n && !isNaN(n) }
module.exports = function (file, opts) {
if (!opts) opts = {}
//file, blocks, frame, codec
if (typeof opts !== 'object')
opts = legacy.apply(null, arguments)
var blockSize = opts.blockSize || 1024*16
var codec = opts.codec || {encode: id, decode: id, buffer: true}
var cache = opts.cache || Cache(1024)
var offsetCodec = opts.offsetCodec || 32
var blocks = Blocks(file, blockSize, opts.flags, cache)
var frame = createFrame(blocks, blockSize, offsetCodec)
return inject(blocks, frame, codec, file)
}
var warned = false
var msg = 'flumelog-offset: blockSize and codec params moved into an object. https://github.com/flumedb/flumelog-offset'
function legacy (file, blockSize, codec) {
if (!warned) warned = true, console.warn(msg)
if (!isNumber(blockSize)) codec = blockSize, blockSize = undefined
return {blockSize: blockSize, codec: codec}
}