summaryrefslogtreecommitdiff
path: root/cli/js/streams/strategies.ts
blob: 5f7ffc6324f5128464da6672b51e86f2336a5f8e (plain)
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
36
37
38
39
// Forked from https://github.com/stardazed/sd-streams/tree/8928cf04b035fd02fb1340b7eb541c76be37e546
// Copyright (c) 2018-Present by Arthur Langereis - @zenmumbler MIT

/**
 * streams/strategies - implementation of the built-in stream strategies
 * Part of Stardazed
 * (c) 2018-Present by Arthur Langereis - @zenmumbler
 * https://github.com/stardazed/sd-streams
 */

/* eslint-disable @typescript-eslint/no-explicit-any */
// TODO reenable this lint here

import { QueuingStrategy } from "../dom_types.ts";

export class ByteLengthQueuingStrategy
  implements QueuingStrategy<ArrayBufferView> {
  highWaterMark: number;

  constructor(options: { highWaterMark: number }) {
    this.highWaterMark = options.highWaterMark;
  }

  size(chunk: ArrayBufferView): number {
    return chunk.byteLength;
  }
}

export class CountQueuingStrategy implements QueuingStrategy<any> {
  highWaterMark: number;

  constructor(options: { highWaterMark: number }) {
    this.highWaterMark = options.highWaterMark;
  }

  size(): number {
    return 1;
  }
}