[**@jupyterlite**](../../../README.md) *** [@jupyterlite](../../../README.md) / [@jupyterlite/services](../README.md) / BrowserStorageDrive # Class: BrowserStorageDrive Defined in: [packages/services/src/contents/drive.ts:140](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L140) A custom drive to store files in the browser storage. ## Implements - `IDrive` ## Constructors ### Constructor > **new BrowserStorageDrive**(`options`): `BrowserStorageDrive` Defined in: [packages/services/src/contents/drive.ts:144](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L144) Construct a new localForage-powered contents provider #### Parameters ##### options [`IOptions`](../namespaces/BrowserStorageDrive/interfaces/IOptions.md) #### Returns `BrowserStorageDrive` ## Properties ### contentProviderRegistry > `readonly` **contentProviderRegistry**: `ContentProviderRegistry` Defined in: [packages/services/src/contents/drive.ts:164](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L164) **`Experimental`** Content provider registry. #### Implementation of `Contents.IDrive.contentProviderRegistry` ## Accessors ### checkpoints #### Get Signature > **get** `protected` **checkpoints**(): `Promise`\<`LocalForage`\> Defined in: [packages/services/src/contents/drive.ts:284](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L284) A lazy reference to the underlying checkpoints. ##### Returns `Promise`\<`LocalForage`\> *** ### counters #### Get Signature > **get** `protected` **counters**(): `Promise`\<`LocalForage`\> Defined in: [packages/services/src/contents/drive.ts:277](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L277) A lazy reference to the underlying counters. ##### Returns `Promise`\<`LocalForage`\> *** ### defaultStorageOptions #### Get Signature > **get** `protected` **defaultStorageOptions**(): `LocalForageOptions` Defined in: [packages/services/src/contents/drive.ts:291](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L291) Get default options for localForage instances ##### Returns `LocalForageOptions` *** ### fileChanged #### Get Signature > **get** **fileChanged**(): `ISignal`\<`IDrive`, `IChangedArgs`\> Defined in: [packages/services/src/contents/drive.ts:201](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L201) Signal emitted when a file operation takes place. ##### Returns `ISignal`\<`IDrive`, `IChangedArgs`\> #### Implementation of `Contents.IDrive.fileChanged` *** ### isDisposed #### Get Signature > **get** **isDisposed**(): `boolean` Defined in: [packages/services/src/contents/drive.ts:180](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L180) Whether the drive is disposed. ##### Returns `boolean` #### Implementation of `Contents.IDrive.isDisposed` *** ### name #### Get Signature > **get** **name**(): `string` Defined in: [packages/services/src/contents/drive.ts:187](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L187) The name of the drive. ##### Returns `string` #### Implementation of `Contents.IDrive.name` *** ### ready #### Get Signature > **get** **ready**(): `Promise`\<`void`\> Defined in: [packages/services/src/contents/drive.ts:263](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L263) A promise that resolves once all storage is fully initialized. ##### Returns `Promise`\<`void`\> *** ### serverSettings #### Get Signature > **get** **serverSettings**(): `ISettings` Defined in: [packages/services/src/contents/drive.ts:194](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L194) The server settings of the drive. ##### Returns `ISettings` #### Implementation of `Contents.IDrive.serverSettings` *** ### storage #### Get Signature > **get** `protected` **storage**(): `Promise`\<`LocalForage`\> Defined in: [packages/services/src/contents/drive.ts:270](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L270) A lazy reference to the underlying storage. ##### Returns `Promise`\<`LocalForage`\> ## Methods ### clearStorage() > **clearStorage**(): `Promise`\<`void`\> Defined in: [packages/services/src/contents/drive.ts:339](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L339) Clear all storage (files, counters, and checkpoints). #### Returns `Promise`\<`void`\> A promise which resolves when all storage is cleared. *** ### copy() > **copy**(`path`, `toDir`): `Promise`\<`IModel`\> Defined in: [packages/services/src/contents/drive.ts:460](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L460) Copy a file into a given directory. #### Parameters ##### path `string` The original file path. ##### toDir `string` The destination directory path. #### Returns `Promise`\<`IModel`\> A promise which resolves with the new contents model when the file is copied. #### Notes The server will select the name of the copied file. #### Implementation of `Contents.IDrive.copy` *** ### createCheckpoint() > **createCheckpoint**(`path`): `Promise`\<`ICheckpointModel`\> Defined in: [packages/services/src/contents/drive.ts:851](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L851) Create a checkpoint for a file. #### Parameters ##### path `string` The path of the file. #### Returns `Promise`\<`ICheckpointModel`\> A promise which resolves with the new checkpoint model when the checkpoint is created. #### Implementation of `Contents.IDrive.createCheckpoint` *** ### createDefaultCheckpoints() > `protected` **createDefaultCheckpoints**(): `LocalForage` Defined in: [packages/services/src/contents/drive.ts:326](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L326) Create the default checkpoint storage. #### Returns `LocalForage` *** ### createDefaultCounters() > `protected` **createDefaultCounters**(): `LocalForage` Defined in: [packages/services/src/contents/drive.ts:315](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L315) Initialize the default storage for counting file suffixes. #### Returns `LocalForage` *** ### createDefaultStorage() > `protected` **createDefaultStorage**(): `LocalForage` Defined in: [packages/services/src/contents/drive.ts:304](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L304) Initialize the default storage for contents. #### Returns `LocalForage` *** ### delete() > **delete**(`path`): `Promise`\<`void`\> Defined in: [packages/services/src/contents/drive.ts:817](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L817) Delete a file from browser storage. Has no effect on server-backed files, which will re-appear with their original timestamp. #### Parameters ##### path `string` The path to the file. #### Returns `Promise`\<`void`\> #### Implementation of `Contents.IDrive.delete` *** ### deleteCheckpoint() > **deleteCheckpoint**(`path`, `checkpointID`): `Promise`\<`void`\> Defined in: [packages/services/src/contents/drive.ts:912](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L912) Delete a checkpoint for a file. #### Parameters ##### path `string` The path of the file. ##### checkpointID `string` The id of the checkpoint to delete. #### Returns `Promise`\<`void`\> A promise which resolves when the checkpoint is deleted. #### Implementation of `Contents.IDrive.deleteCheckpoint` *** ### dispose() > **dispose**(): `void` Defined in: [packages/services/src/contents/drive.ts:169](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L169) Dispose the drive. #### Returns `void` #### Implementation of `Contents.IDrive.dispose` *** ### forgetPath() > `protected` **forgetPath**(`path`): `Promise`\<`void`\> Defined in: [packages/services/src/contents/drive.ts:836](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L836) Remove the localForage and checkpoints for a path. #### Parameters ##### path `string` The path to the file #### Returns `Promise`\<`void`\> *** ### get() > **get**(`path`, `options?`): `Promise`\<`IModel`\> Defined in: [packages/services/src/contents/drive.ts:503](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L503) Get a file or directory. #### Parameters ##### path `string` ##### options? `IFetchOptions` #### Returns `Promise`\<`IModel`\> A promise which resolves with the file content. #### Implementation of `Contents.IDrive.get` *** ### getDownloadUrl() > **getDownloadUrl**(`path`): `Promise`\<`string`\> Defined in: [packages/services/src/contents/drive.ts:208](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L208) Get the download URL #### Parameters ##### path `string` #### Returns `Promise`\<`string`\> #### Implementation of `Contents.IDrive.getDownloadUrl` *** ### initialize() > **initialize**(): `Promise`\<`void`\> Defined in: [packages/services/src/contents/drive.ts:246](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L246) Finish any initialization after server has started and all extensions are applied. TODO: keep private? #### Returns `Promise`\<`void`\> *** ### initStorage() > `protected` **initStorage**(): `Promise`\<`void`\> Defined in: [packages/services/src/contents/drive.ts:254](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L254) Initialize all storage instances #### Returns `Promise`\<`void`\> *** ### listCheckpoints() > **listCheckpoints**(`path`): `Promise`\<`ICheckpointModel`[]\> Defined in: [packages/services/src/contents/drive.ts:879](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L879) List available checkpoints for a file. #### Parameters ##### path `string` The path of the file. #### Returns `Promise`\<`ICheckpointModel`[]\> A promise which resolves with a list of checkpoint models for the file. #### Implementation of `Contents.IDrive.listCheckpoints` *** ### newUntitled() > **newUntitled**(`options?`): `Promise`\<`IModel`\> Defined in: [packages/services/src/contents/drive.ts:354](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L354) Create a new untitled file or directory in the specified directory path. #### Parameters ##### options? `ICreateOptions` #### Returns `Promise`\<`IModel`\> A promise which resolves with the created file content when the file is created. #### Implementation of `Contents.IDrive.newUntitled` *** ### normalizeCheckpoint() > `protected` **normalizeCheckpoint**(`model`, `id`): `ICheckpointModel` Defined in: [packages/services/src/contents/drive.ts:884](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L884) #### Parameters ##### model `IModel` ##### id `number` #### Returns `ICheckpointModel` *** ### reduceBytesToString() > `protected` **reduceBytesToString**(`data`, `byte`): `string` Defined in: [packages/services/src/contents/drive.ts:1084](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L1084) A reducer for turning arbitrary binary into a string #### Parameters ##### data `string` ##### byte `number` #### Returns `string` *** ### rename() > **rename**(`oldLocalPath`, `newLocalPath`): `Promise`\<`IModel`\> Defined in: [packages/services/src/contents/drive.ts:608](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L608) Rename a file or directory. #### Parameters ##### oldLocalPath `string` The original file path. ##### newLocalPath `string` The new file path. #### Returns `Promise`\<`IModel`\> A promise which resolves with the new file content model when the file is renamed. #### Implementation of `Contents.IDrive.rename` *** ### restoreCheckpoint() > **restoreCheckpoint**(`path`, `checkpointID`): `Promise`\<`void`\> Defined in: [packages/services/src/contents/drive.ts:896](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L896) Restore a file to a known checkpoint state. #### Parameters ##### path `string` The path of the file. ##### checkpointID `string` The id of the checkpoint to restore. #### Returns `Promise`\<`void`\> A promise which resolves when the checkpoint is restored. #### Implementation of `Contents.IDrive.restoreCheckpoint` *** ### save() > **save**(`path`, `options`): `Promise`\<`IModel`\> Defined in: [packages/services/src/contents/drive.ts:657](https://github.com/jupyterlite/jupyterlite/blob/5d565b7c8e2c6a07c22d592b848261a0d170de64/packages/services/src/contents/drive.ts#L657) Save a file. #### Parameters ##### path `string` The desired file path. ##### options `Partial`\<`IModel`\> & `IContentProvisionOptions` = `{}` Optional overrides to the model. #### Returns `Promise`\<`IModel`\> A promise which resolves with the file content model when the file is saved. #### Implementation of `Contents.IDrive.save`