forked from libapps/libapps-mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnassh_buffer.js
More file actions
48 lines (42 loc) · 1.15 KB
/
nassh_buffer.js
File metadata and controls
48 lines (42 loc) · 1.15 KB
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
40
41
42
43
44
45
46
47
48
// Copyright 2020 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview Core buffer related logic.
*/
import {ConcatBuffer} from './nassh_buffer_concat.js';
import {BufferInterface} from './nassh_buffer_interface.js';
import {ScatGatBuffer} from './nassh_buffer_scatgat.js';
/**
* The buffer backend to use.
*/
let defaultBackend = 'scatgat';
/**
* Set default backend for all buffer users.
*
* This allows for runtime experimentation without affecting the defaults.
*
* @param {string} backend The new backend to use.
*/
export function setDefaultBackend(backend) {
defaultBackend = backend;
}
/**
* Allocates a new buffer and returns it.
*
* This respects the dynamic backend selection.
*
* @param {...*} args
* @return {!BufferInterface}
*/
export function newBuffer(...args) {
switch (defaultBackend) {
case 'concat':
return new ConcatBuffer(...args);
default:
console.warn(`Unknown buffer type '${defaultBackend}'; ` +
`using 'scatgat' instead.`);
case 'scatgat':
return new ScatGatBuffer(...args);
}
}