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

Class HTML5FS

src/backend/HTML5FS.ts:158–532  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

156 * only available in Chrome.
157 */
158export default class HTML5FS extends BaseFileSystem implements IFileSystem {
159 public static readonly Name = "HTML5FS";
160
161 public static readonly Options: FileSystemOptions = {
162 size: {
163 type: "number",
164 optional: true,
165 description: "Storage quota to request, in megabytes. Allocated value may be less. Defaults to 5."
166 },
167 type: {
168 type: "number",
169 optional: true,
170 description: "window.PERSISTENT or window.TEMPORARY. Defaults to PERSISTENT."
171 }
172 };
173
174 /**
175 * Creates an HTML5FS instance with the given options.
176 */
177 public static Create(opts: HTML5FSOptions, cb: BFSCallback<HTML5FS>): void {
178 const fs = new HTML5FS(opts.size, opts.type, false);
179 fs.allocate((e) => e ? cb(e) : cb(null, fs), false);
180 }
181 public static isAvailable(): boolean {
182 return !!_getFS;
183 }
184
185 // HTML5File reaches into HTML5FS. :/
186 public fs: FileSystem;
187 private size: number;
188 private type: number;
189 /**
190 * **Deprecated. Please use HTML5FS.Create() method instead.**
191 *
192 * Creates a new HTML5 FileSystem-backed BrowserFS file system of the given size
193 * and storage type.
194 *
195 * **IMPORTANT**: You must call `allocate` on the resulting object before the file system
196 * can be used.
197 *
198 * @param size storage quota to request, in megabytes. Allocated value may be less.
199 * @param type window.PERSISTENT or window.TEMPORARY. Defaults to PERSISTENT.
200 */
201 constructor(size: number = 5, type: number = global.PERSISTENT, deprecateMsg = true) {
202 super();
203 // Convert MB to bytes.
204 this.size = 1024 * 1024 * size;
205 this.type = type;
206 deprecationMessage(deprecateMsg, HTML5FS.Name, {size: size, type: type});
207 }
208
209 public getName(): string {
210 return HTML5FS.Name;
211 }
212
213 public isReadOnly(): boolean {
214 return false;
215 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected