<commit_before>_u          = require 'underscore'
Concentrate = require "concentrate"
Dissolve    = require "dissolve"
nconf       = require "nconf"

Rewinder        = require "./rewind/rewinder"
HLSSegmenter    = require "./rewind/hls_segmenter"

MemoryStore     = require "./rewind/memory_store"

# RewindBuffer supports play from an arbitrary position in the last X hours
# of our stream.

# Buffer is an array of objects. Each object should have:
# * ts:         Timestamp for when chunk was emitted from master stream
# * data:       Chunk of audio data (in either MP3 or AAC)
# * meta:       Metadata that should be running as of this chunk
# * duration:   Duration of the audio chunk

# When the buffer is dumped, it will be in the form of a loop of binary
# packets.  Each will contain:
# * uint8: metadata length
# * Buffer: metadata, stringified into JSON and stuck in a buffer (obj is ts,
#   duration and meta)
# * uint16: data length
# * Buffer: data chunk

module.exports = class RewindBuffer extends require("events").EventEmitter
    constructor: (rewind_opts={}) ->
        @_rsecs         = rewind_opts.seconds || 0
        @_rburstsecs    = rewind_opts.burst || 0
        @_rsecsPerChunk = Infinity
        @_rmax          = null
        @_rburst        = null

        @log            = rewind_opts.log

        # each listener should be an object that defines obj._offset and
        # obj.writeFrame. We implement RewindBuffer.Listener, but other
        # classes can work with those pieces
        @_rlisteners = []

        # create buffer as an array<commit_msg>RewindBuffer: Fix how log is defined<commit_after>_u          = require 'underscore'
Concentrate = require "concentrate"
Dissolve    = require "dissolve"
nconf       = require "nconf"

Rewinder        = require "./rewind/rewinder"
HLSSegmenter    = require "./rewind/hls_segmenter"

MemoryStore     = require "./rewind/memory_store"

# RewindBuffer supports play from an arbitrary position in the last X hours
# of our stream.

# Buffer is an array of objects. Each object should have:
# * ts:         Timestamp for when chunk was emitted from master stream
# * data:       Chunk of audio data (in either MP3 or AAC)
# * meta:       Metadata that should be running as of this chunk
# * duration:   Duration of the audio chunk

# When the buffer is dumped, it will be in the form of a loop of binary
# packets.  Each will contain:
# * uint8: metadata length
# * Buffer: metadata, stringified into JSON and stuck in a buffer (obj is ts,
#   duration and meta)
# * uint16: data length
# * Buffer: data chunk

module.exports = class RewindBuffer extends require("events").EventEmitter
    constructor: (rewind_opts={}) ->
        @_rsecs         = rewind_opts.seconds || 0
        @_rburstsecs    = rewind_opts.burst || 0
        @_rsecsPerChunk = Infinity
        @_rmax          = null
        @_rburst        = null

        # This could already be set if we've subclassed RewindBuffer, so
        # only set it if it doesn't exist
        @log            = rewind_opts.log if rewind_opts.log && !@log

        # each listener should be an object that defines obj._offset and
        # obj.writeFrame. We implement RewindBuffer.Listener, but other
        # classes can work with those pieces
        @_rlisteners = []

        # create buffer as an array
{'fraction_non_alphanumeric': 0.0763016157989228, 'fraction_numerical': 0.003590664272890485, 'mean_word_length': 2.625813449023861, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4611627', 'n_tokens_mistral': 976, 'n_tokens_neox': 934, 'n_words': 376}