# Class: `Contents` [@jupyterlite/contents](../modules/jupyterlite_contents.md).Contents A class to handle requests to /api/contents ## Implements - [`IContents`](../modules/jupyterlite_contents.md#icontents) ## Constructors ### `constructor` > > **`new Contents`**(`options`) Construct a new localForage-powered contents provider #### Parameters | Name | Type | | :------ | :------ | | `options` | [`IOptions`](../interfaces/jupyterlite_contents.Contents.IOptions.md) | #### Defined in [packages/contents/src/contents.ts:33](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L33) ## Properties ### `_checkpoints` > > `Private` **`_checkpoints`**: `undefined` \| `LocalForage` #### Defined in [packages/contents/src/contents.ts:816](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L816) ### `_counters` > > `Private` **`_counters`**: `undefined` \| `LocalForage` #### Defined in [packages/contents/src/contents.ts:815](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L815) ### `_localforage` > > `Private` **`_localforage`**: `LocalForage` #### Defined in [packages/contents/src/contents.ts:817](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L817) ### `_ready` > > `Private` **`_ready`**: `PromiseDelegate`<`void`\> #### Defined in [packages/contents/src/contents.ts:813](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L813) ### `_serverContents` > > `Private` **`_serverContents`**: `Map`<`string`, `Map`<`string`, `IModel`\>\> #### Defined in [packages/contents/src/contents.ts:810](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L810) ### `_storage` > > `Private` **`_storage`**: `undefined` \| `LocalForage` #### Defined in [packages/contents/src/contents.ts:814](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L814) ### `_storageDrivers` > > `Private` **`_storageDrivers`**: ``null`` \| `string`[] = `null` #### Defined in [packages/contents/src/contents.ts:812](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L812) ### `_storageName` > > `Private` **`_storageName`**: `string` = `DEFAULT_STORAGE_NAME` #### Defined in [packages/contents/src/contents.ts:811](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L811) ## Accessors ### `checkpoints` > > `Protected` `get` **`checkpoints`**(): `Promise`<`LocalForage`\> A lazy reference to the underlying checkpoints. #### Returns `Promise`<`LocalForage`\> #### Defined in [packages/contents/src/contents.ts:81](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L81) ### `counters` > > `Protected` `get` **`counters`**(): `Promise`<`LocalForage`\> A lazy reference to the underlying counters. #### Returns `Promise`<`LocalForage`\> #### Defined in [packages/contents/src/contents.ts:74](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L74) ### `defaultStorageOptions` > > `Protected` `get` **`defaultStorageOptions`**(): `LocalForageOptions` Get default options for localForage instances #### Returns `LocalForageOptions` #### Defined in [packages/contents/src/contents.ts:88](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L88) ### `ready` > > `get` **`ready`**(): `Promise`<`void`\> A promise that resolves once all storage is fully initialized. #### Returns `Promise`<`void`\> #### Implementation of IContents.ready #### Defined in [packages/contents/src/contents.ts:60](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L60) ### `storage` > > `Protected` `get` **`storage`**(): `Promise`<`LocalForage`\> A lazy reference to the underlying storage. #### Returns `Promise`<`LocalForage`\> #### Defined in [packages/contents/src/contents.ts:67](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L67) ## Methods ### `_getFolder` > > `Private` **`_getFolder`**(`path`): `Promise`<``null`` \| `IModel`\> retrieve the contents for this path from the union of local storage and `api/contents/{path}/all.json`. #### Parameters | Name | Type | Description | | :------ | :------ | :------ | | `path` | `string` | The contents path to retrieve | #### Returns `Promise`<``null`` \| `IModel`\> A promise which resolves with a Map of contents, keyed by local file name #### Defined in [packages/contents/src/contents.ts:636](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L636) ### `_getServerContents` > > `Private` **`_getServerContents`**(`path`, `options?`): `Promise`<``null`` \| `IModel`\> Attempt to recover the model from `{:path}/__all__.json` file, fall back to deriving the model (including content) off the file in `/files/`. Otherwise return `null`. #### Parameters | Name | Type | | :------ | :------ | | `path` | `string` | | `options?` | `IFetchOptions` | #### Returns `Promise`<``null`` \| `IModel`\> #### Defined in [packages/contents/src/contents.ts:676](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L676) ### `_getServerDirectory` > > `Private` **`_getServerDirectory`**(`path`): `Promise`<`Map`<`string`, `IModel`\>\> retrieve the contents for this path from `__index__.json` in the appropriate folder. #### Parameters | Name | Type | | :------ | :------ | | `path` | `string` | #### Returns `Promise`<`Map`<`string`, `IModel`\>\> A promise which resolves with a Map of contents, keyed by local file name #### Defined in [packages/contents/src/contents.ts:767](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L767) ### `_handleBinaryChunk` > > `Private` **`_handleBinaryChunk`**(`newContent`, `originalContent`, `chunked?`): `string` Handle a chunk of a binary file. each chunk is base64 encoded, so we need to decode it and append it to the original content. if the chunk has padding, we need to remove it before appending. #### Parameters | Name | Type | | :------ | :------ | | `newContent` | `string` | | `originalContent` | `string` | | `chunked?` | `boolean` | #### Returns `string` the decoded string, appended to the original content if chunked / #### Defined in [packages/contents/src/contents.ts:617](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L617) ### `_handleChunk` > > `Private` **`_handleChunk`**(`newContent`, `originalContent`, `chunked?`): `string` Handle a chunk of a file. Decode and unescape a base64-encoded string. #### Parameters | Name | Type | | :------ | :------ | | `newContent` | `string` | | `originalContent` | `string` | | `chunked?` | `boolean` | #### Returns `string` the decoded string, appended to the original content if chunked / #### Defined in [packages/contents/src/contents.ts:597](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L597) ### `_incrementCounter` > > `Private` **`_incrementCounter`**(`type`): `Promise`<`number`\> Increment the counter for a given file type. Used to avoid collisions when creating new untitled files. #### Parameters | Name | Type | Description | | :------ | :------ | :------ | | `type` | `string` | The file type to increment the counter for. | #### Returns `Promise`<`number`\> #### Defined in [packages/contents/src/contents.ts:802](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L802) ### `copy` > > **`copy`**(`path`, `toDir`): `Promise`<`IModel`\> Copy a file into a given directory. #### Parameters | Name | Type | Description | | :------ | :------ | :------ | | `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 IContents.copy #### Defined in [packages/contents/src/contents.ts:249](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L249) ### `createCheckpoint` > > **`createCheckpoint`**(`path`): `Promise`<`ICheckpointModel`\> Create a checkpoint for a file. #### Parameters | Name | Type | Description | | :------ | :------ | :------ | | `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 IContents.createCheckpoint #### Defined in [packages/contents/src/contents.ts:517](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L517) ### `createDefaultCheckpoints` > > `Protected` **`createDefaultCheckpoints`**(): `LocalForage` Create the default checkpoint storage. #### Returns `LocalForage` #### Defined in [packages/contents/src/contents.ts:123](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L123) ### `createDefaultCounters` > > `Protected` **`createDefaultCounters`**(): `LocalForage` Initialize the default storage for counting file suffixes. #### Returns `LocalForage` #### Defined in [packages/contents/src/contents.ts:112](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L112) ### `createDefaultStorage` > > `Protected` **`createDefaultStorage`**(): `LocalForage` Initialize the default storage for contents. #### Returns `LocalForage` #### Defined in [packages/contents/src/contents.ts:101](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L101) ### `delete` > > **`delete`**(`path`): `Promise`<`void`\> Delete a file from browser storage. Has no effect on server-backed files, which will re-appear with their original timestamp. #### Parameters | Name | Type | Description | | :------ | :------ | :------ | | `path` | `string` | The path to the file. | #### Returns `Promise`<`void`\> #### Implementation of IContents.delete #### Defined in [packages/contents/src/contents.ts:488](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L488) ### `deleteCheckpoint` > > **`deleteCheckpoint`**(`path`, `checkpointID`): `Promise`<`void`\> Delete a checkpoint for a file. #### Parameters | Name | Type | Description | | :------ | :------ | :------ | | `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 IContents.deleteCheckpoint #### Defined in [packages/contents/src/contents.ts:581](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L581) ### `forgetPath` > > `Protected` **`forgetPath`**(`path`): `Promise`<`void`\> Remove the localForage and checkpoints for a path. #### Parameters | Name | Type | Description | | :------ | :------ | :------ | | `path` | `string` | The path to the file | #### Returns `Promise`<`void`\> #### Defined in [packages/contents/src/contents.ts:502](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L502) ### `get` > > **`get`**(`path`, `options?`): `Promise`<``null`` \| `IModel`\> Get a file or directory. #### Parameters | Name | Type | | :------ | :------ | | `path` | `string` | | `options?` | `IFetchOptions` | #### Returns `Promise`<``null`` \| `IModel`\> A promise which resolves with the file content. #### Implementation of IContents.get #### Defined in [packages/contents/src/contents.ts:280](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L280) ### `initStorage` > > `Protected` **`initStorage`**(): `Promise`<`void`\> Initialize all storage instances #### Returns `Promise`<`void`\> #### Defined in [packages/contents/src/contents.ts:51](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L51) ### `initialize` > > **`initialize`**(): `Promise`<`void`\> Finish any initialization after server has started and all extensions are applied. #### Returns `Promise`<`void`\> #### Defined in [packages/contents/src/contents.ts:43](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L43) ### `listCheckpoints` > > **`listCheckpoints`**(`path`): `Promise`<`ICheckpointModel`[]\> List available checkpoints for a file. #### Parameters | Name | Type | Description | | :------ | :------ | :------ | | `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 IContents.listCheckpoints #### Defined in [packages/contents/src/contents.ts:545](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L545) ### `newUntitled` > > **`newUntitled`**(`options?`): `Promise`<``null`` \| `IModel`\> Create a new untitled file or directory in the specified directory path. #### Parameters | Name | Type | | :------ | :------ | | `options?` | `ICreateOptions` | #### Returns `Promise`<``null`` \| `IModel`\> A promise which resolves with the created file content when the file is created. #### Implementation of IContents.newUntitled #### Defined in [packages/contents/src/contents.ts:138](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L138) ### `normalizeCheckpoint` > > `Protected` **`normalizeCheckpoint`**(`model`, `id`): `ICheckpointModel` #### Parameters | Name | Type | | :------ | :------ | | `model` | `IModel` | | `id` | `number` | #### Returns `ICheckpointModel` #### Defined in [packages/contents/src/contents.ts:550](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L550) ### `reduceBytesToString` > > `Protected` **`reduceBytesToString`**(`data`, `byte`): `string` A reducer for turning arbitrary binary into a string #### Parameters | Name | Type | | :------ | :------ | | `data` | `string` | | `byte` | `number` | #### Returns `string` #### Defined in [packages/contents/src/contents.ts:755](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L755) ### `rename` > > **`rename`**(`oldLocalPath`, `newLocalPath`): `Promise`<`IModel`\> Rename a file or directory. #### Parameters | Name | Type | Description | | :------ | :------ | :------ | | `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 IContents.rename #### Defined in [packages/contents/src/contents.ts:354](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L354) ### `restoreCheckpoint` > > **`restoreCheckpoint`**(`path`, `checkpointID`): `Promise`<`void`\> Restore a file to a known checkpoint state. #### Parameters | Name | Type | Description | | :------ | :------ | :------ | | `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 IContents.restoreCheckpoint #### Defined in [packages/contents/src/contents.ts:565](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L565) ### `save` > > **`save`**(`path`, `options?`): `Promise`<``null`` \| `IModel`\> Save a file. #### Parameters | Name | Type | Description | | :------ | :------ | :------ | | `path` | `string` | The desired file path. | | `options` | `Partial`<`IModel`\> | Optional overrides to the model. | #### Returns `Promise`<``null`` \| `IModel`\> A promise which resolves with the file content model when the file is saved. #### Implementation of IContents.save #### Defined in [packages/contents/src/contents.ts:396](https://github.com/jupyterlite/jupyterlite/blob/999c7f0/packages/contents/src/contents.ts#L396)