Blame view

node_modules/m3u8-parser/src/line-stream.js 726 Bytes
2a09d1a4   liuqimichale   添加宜春 天水 宣化
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
31
32
33
34
35
  /**
   * @file m3u8/line-stream.js
   */
  import Stream from './stream';
  
  /**
   * A stream that buffers string input and generates a `data` event for each
   * line.
   *
   * @class LineStream
   * @extends Stream
   */
  export default class LineStream extends Stream {
    constructor() {
      super();
      this.buffer = '';
    }
  
    /**
     * Add new data to be parsed.
     *
     * @param {String} data the text to process
     */
    push(data) {
      let nextNewline;
  
      this.buffer += data;
      nextNewline = this.buffer.indexOf('\n');
  
      for (; nextNewline > -1; nextNewline = this.buffer.indexOf('\n')) {
        this.trigger('data', this.buffer.substring(0, nextNewline));
        this.buffer = this.buffer.substring(nextNewline + 1);
      }
    }
  }