MCPcopy
hub / github.com/jvilk/BrowserFS / constructor

Method constructor

src/generic/preload_file.ts:40–59  ·  view source on GitHub ↗

* Creates a file with the given path and, optionally, the given contents. Note * that, if contents is specified, it will be mutated by the file! * @param _fs The file system that created the file. * @param _path * @param _mode The mode that the file was opened using. * Dictates perm

(_fs: T, _path: string, _flag: FileFlag, _stat: Stats, contents?: Buffer)

Source from the content-addressed store, hash-verified

38 * specified, we assume it is a new file.
39 */
40 constructor(_fs: T, _path: string, _flag: FileFlag, _stat: Stats, contents?: Buffer) {
41 super();
42 this._fs = _fs;
43 this._path = _path;
44 this._flag = _flag;
45 this._stat = _stat;
46 if (contents) {
47 this._buffer = contents;
48 } else {
49 // Empty buffer. It'll expand once we write stuff to it.
50 this._buffer = emptyBuffer();
51 }
52 // Note: This invariant is *not* maintained once the file starts getting
53 // modified.
54 // Note: Only actually matters if file is readable, as writeable modes may
55 // truncate/append to file.
56 if (this._stat.size !== this._buffer.length && this._flag.isReadable()) {
57 throw new Error(`Invalid buffer: Buffer is ${this._buffer.length} long, yet Stats object specifies that file is ${this._stat.size} long.`);
58 }
59 }
60
61 /**
62 * NONSTANDARD: Get the underlying buffer for this file. !!DO NOT MUTATE!! Will mess up dirty tracking.

Callers

nothing calls this directly

Calls 2

emptyBufferFunction · 0.90
isReadableMethod · 0.80

Tested by

no test coverage detected