Skip to content

Commit 621535e

Browse files
authored
Merge pull request #1326 from remotestorage/docs/1310-mime_type
Fix get/storeFile docs and function argument name
2 parents a4bebfa + 4446ede commit 621535e

File tree

2 files changed

+40
-37
lines changed

2 files changed

+40
-37
lines changed

docs/api/baseclient/classes/BaseClient.md

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ A `BaseClient` deals with three types of data: folders, objects and files.
2121
* [getObject](BaseClient.md#getobject) and [storeObject](BaseClient.md#storeobject) operate on JSON objects. Each object
2222
has a type.
2323

24-
* [getFile](BaseClient.md#getfile) and [storeFile](BaseClient.md#storefile) operates on files. Each file has a MIME
25-
type.
24+
* [getFile](BaseClient.md#getfile) and [storeFile](BaseClient.md#storefile) operates on files. Each file has a
25+
content/MIME type.
2626

2727
* [getAll](BaseClient.md#getall) returns all objects or files for the given folder path.
2828

@@ -223,7 +223,7 @@ corresponding `publicClient` it is `/public/<moduleName>/`.
223223

224224
#### Defined in
225225

226-
[baseclient.ts:239](https://github.com/remotestorage/remotestorage.js/blob/a199c15fb409a17fd444aa7fba846e7fecc5981d/src/baseclient.ts#L239)
226+
[baseclient.ts:239](https://github.com/remotestorage/remotestorage.js/blob/a883b85da66e86fad01e632f66b390973ef0772e/src/baseclient.ts#L239)
227227

228228
## Methods
229229

@@ -247,7 +247,7 @@ Usually called via [`on()`](#on)
247247

248248
#### Defined in
249249

250-
[eventhandling.ts:29](https://github.com/remotestorage/remotestorage.js/blob/a199c15fb409a17fd444aa7fba846e7fecc5981d/src/eventhandling.ts#L29)
250+
[eventhandling.ts:29](https://github.com/remotestorage/remotestorage.js/blob/a883b85da66e86fad01e632f66b390973ef0772e/src/eventhandling.ts#L29)
251251

252252
***
253253

@@ -286,7 +286,7 @@ client.cache('lists/', 'SEEN');
286286

287287
#### Defined in
288288

289-
[baseclient.ts:683](https://github.com/remotestorage/remotestorage.js/blob/a199c15fb409a17fd444aa7fba846e7fecc5981d/src/baseclient.ts#L683)
289+
[baseclient.ts:684](https://github.com/remotestorage/remotestorage.js/blob/a883b85da66e86fad01e632f66b390973ef0772e/src/baseclient.ts#L684)
290290

291291
***
292292

@@ -344,7 +344,7 @@ client.declareType('todo-item', {
344344

345345
#### Defined in
346346

347-
[baseclient.ts:733](https://github.com/remotestorage/remotestorage.js/blob/a199c15fb409a17fd444aa7fba846e7fecc5981d/src/baseclient.ts#L733)
347+
[baseclient.ts:734](https://github.com/remotestorage/remotestorage.js/blob/a883b85da66e86fad01e632f66b390973ef0772e/src/baseclient.ts#L734)
348348

349349
***
350350

@@ -420,7 +420,7 @@ Example response:
420420
421421
#### Defined in
422422

423-
[baseclient.ts:395](https://github.com/remotestorage/remotestorage.js/blob/a199c15fb409a17fd444aa7fba846e7fecc5981d/src/baseclient.ts#L395)
423+
[baseclient.ts:395](https://github.com/remotestorage/remotestorage.js/blob/a883b85da66e86fad01e632f66b390973ef0772e/src/baseclient.ts#L395)
424424

425425
***
426426

@@ -449,8 +449,10 @@ Relative path from the module root (without leading slash).
449449

450450
An object containing the content type as well as the file's content:
451451

452-
* `mimeType`<br>
453-
String representing the MIME Type of the document.
452+
* `contentType`<br>
453+
String containing the MIME Type of the document. (Usually just the
454+
MIME type, but can theoretically contain extra metadata such as `charset`
455+
for example.)
454456
* `data`<br>
455457
Raw data of the document (either a string or an ArrayBuffer)
456458

@@ -460,15 +462,15 @@ Displaying an image:
460462

461463
```js
462464
client.getFile('path/to/some/image').then(file => {
463-
const blob = new Blob([file.data], { type: file.mimeType });
465+
const blob = new Blob([file.data], { type: file.contentType });
464466
const targetElement = document.findElementById('my-image-element');
465467
targetElement.src = window.URL.createObjectURL(blob);
466468
});
467469
```
468470

469471
#### Defined in
470472

471-
[baseclient.ts:456](https://github.com/remotestorage/remotestorage.js/blob/a199c15fb409a17fd444aa7fba846e7fecc5981d/src/baseclient.ts#L456)
473+
[baseclient.ts:457](https://github.com/remotestorage/remotestorage.js/blob/a883b85da66e86fad01e632f66b390973ef0772e/src/baseclient.ts#L457)
472474

473475
***
474476

@@ -499,7 +501,7 @@ The full URL of the item, including the storage origin, or `undefined`
499501
500502
#### Defined in
501503

502-
[baseclient.ts:655](https://github.com/remotestorage/remotestorage.js/blob/a199c15fb409a17fd444aa7fba846e7fecc5981d/src/baseclient.ts#L655)
504+
[baseclient.ts:656](https://github.com/remotestorage/remotestorage.js/blob/a883b85da66e86fad01e632f66b390973ef0772e/src/baseclient.ts#L656)
503505

504506
***
505507

@@ -569,7 +571,7 @@ Example of a listing object:
569571
570572
#### Defined in
571573

572-
[baseclient.ts:326](https://github.com/remotestorage/remotestorage.js/blob/a199c15fb409a17fd444aa7fba846e7fecc5981d/src/baseclient.ts#L326)
574+
[baseclient.ts:326](https://github.com/remotestorage/remotestorage.js/blob/a883b85da66e86fad01e632f66b390973ef0772e/src/baseclient.ts#L326)
573575

574576
***
575577

@@ -605,7 +607,7 @@ client.getObject('/path/to/object').then(obj => console.log(obj));
605607

606608
#### Defined in
607609

608-
[baseclient.ts:540](https://github.com/remotestorage/remotestorage.js/blob/a199c15fb409a17fd444aa7fba846e7fecc5981d/src/baseclient.ts#L540)
610+
[baseclient.ts:541](https://github.com/remotestorage/remotestorage.js/blob/a883b85da66e86fad01e632f66b390973ef0772e/src/baseclient.ts#L541)
609611

610612
***
611613

@@ -641,7 +643,7 @@ remoteStorage.on('connected', function() {
641643

642644
#### Defined in
643645

644-
[eventhandling.ts:55](https://github.com/remotestorage/remotestorage.js/blob/a199c15fb409a17fd444aa7fba846e7fecc5981d/src/eventhandling.ts#L55)
646+
[eventhandling.ts:55](https://github.com/remotestorage/remotestorage.js/blob/a883b85da66e86fad01e632f66b390973ef0772e/src/eventhandling.ts#L55)
645647

646648
***
647649

@@ -669,7 +671,7 @@ client.remove('path/to/object').then(() => console.log('item deleted'));
669671

670672
#### Defined in
671673

672-
[baseclient.ts:629](https://github.com/remotestorage/remotestorage.js/blob/a199c15fb409a17fd444aa7fba846e7fecc5981d/src/baseclient.ts#L629)
674+
[baseclient.ts:630](https://github.com/remotestorage/remotestorage.js/blob/a883b85da66e86fad01e632f66b390973ef0772e/src/baseclient.ts#L630)
673675

674676
***
675677

@@ -691,7 +693,7 @@ Remove a previously installed event handler
691693

692694
#### Defined in
693695

694-
[eventhandling.ts:62](https://github.com/remotestorage/remotestorage.js/blob/a199c15fb409a17fd444aa7fba846e7fecc5981d/src/eventhandling.ts#L62)
696+
[eventhandling.ts:62](https://github.com/remotestorage/remotestorage.js/blob/a883b85da66e86fad01e632f66b390973ef0772e/src/eventhandling.ts#L62)
695697

696698
***
697699

@@ -716,21 +718,21 @@ A new `BaseClient` operating on a subpath of the current base path
716718

717719
#### Defined in
718720

719-
[baseclient.ts:272](https://github.com/remotestorage/remotestorage.js/blob/a199c15fb409a17fd444aa7fba846e7fecc5981d/src/baseclient.ts#L272)
721+
[baseclient.ts:272](https://github.com/remotestorage/remotestorage.js/blob/a883b85da66e86fad01e632f66b390973ef0772e/src/baseclient.ts#L272)
720722

721723
***
722724

723725
### storeFile()
724726

725-
> **storeFile**(`mimeType`, `path`, `body`): `Promise`\<`string`\>
727+
> **storeFile**(`contentType`, `path`, `body`): `Promise`\<`string`\>
726728
727729
Store raw data at a given path.
728730

729731
#### Parameters
730732

731-
**mimeType**: `string`
733+
**contentType**: `string`
732734

733-
MIME media type of the data being stored
735+
Content type (MIME media type) of the data being stored
734736

735737
**path**: `string`
736738

@@ -772,7 +774,7 @@ fileReader.readAsArrayBuffer(file);
772774

773775
#### Defined in
774776

775-
[baseclient.ts:502](https://github.com/remotestorage/remotestorage.js/blob/a199c15fb409a17fd444aa7fba846e7fecc5981d/src/baseclient.ts#L502)
777+
[baseclient.ts:503](https://github.com/remotestorage/remotestorage.js/blob/a883b85da66e86fad01e632f66b390973ef0772e/src/baseclient.ts#L503)
776778

777779
***
778780

@@ -825,7 +827,7 @@ client.storeObject('bookmark', path, bookmark)
825827

826828
#### Defined in
827829

828-
[baseclient.ts:588](https://github.com/remotestorage/remotestorage.js/blob/a199c15fb409a17fd444aa7fba846e7fecc5981d/src/baseclient.ts#L588)
830+
[baseclient.ts:589](https://github.com/remotestorage/remotestorage.js/blob/a883b85da66e86fad01e632f66b390973ef0772e/src/baseclient.ts#L589)
829831

830832
***
831833

@@ -862,4 +864,4 @@ var result = client.validate(document);
862864

863865
#### Defined in
864866

865-
[baseclient.ts:765](https://github.com/remotestorage/remotestorage.js/blob/a199c15fb409a17fd444aa7fba846e7fecc5981d/src/baseclient.ts#L765)
867+
[baseclient.ts:766](https://github.com/remotestorage/remotestorage.js/blob/a883b85da66e86fad01e632f66b390973ef0772e/src/baseclient.ts#L766)

src/baseclient.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ function getModuleNameFromBase(path: string): string {
3636
* * {@link getObject} and {@link storeObject} operate on JSON objects. Each object
3737
* has a type.
3838
*
39-
* * {@link getFile} and {@link storeFile} operates on files. Each file has a MIME
40-
* type.
39+
* * {@link getFile} and {@link storeFile} operates on files. Each file has a
40+
* content/MIME type.
4141
*
4242
* * {@link getAll} returns all objects or files for the given folder path.
4343
*
@@ -436,8 +436,10 @@ export class BaseClient {
436436
*
437437
* @returns An object containing the content type as well as the file's content:
438438
*
439-
* * `mimeType`<br>
440-
* String representing the MIME Type of the document.
439+
* * `contentType`<br>
440+
* String containing the MIME Type of the document. (Usually just the
441+
* MIME type, but can theoretically contain extra metadata such as `charset`
442+
* for example.)
441443
* * `data`<br>
442444
* Raw data of the document (either a string or an ArrayBuffer)
443445
*
@@ -446,13 +448,12 @@ export class BaseClient {
446448
*
447449
* ```js
448450
* client.getFile('path/to/some/image').then(file => {
449-
* const blob = new Blob([file.data], { type: file.mimeType });
451+
* const blob = new Blob([file.data], { type: file.contentType });
450452
* const targetElement = document.findElementById('my-image-element');
451453
* targetElement.src = window.URL.createObjectURL(blob);
452454
* });
453455
* ```
454456
*/
455-
// TODO add real return type
456457
async getFile (path: string, maxAge?: false | number): Promise<unknown> {
457458
if (typeof path !== 'string') {
458459
return Promise.reject('Argument \'path\' of baseClient.getFile must be a string');
@@ -470,9 +471,9 @@ export class BaseClient {
470471
/**
471472
* Store raw data at a given path.
472473
*
473-
* @param mimeType - MIME media type of the data being stored
474-
* @param path - Path relative to the module root
475-
* @param body - Raw data to store
474+
* @param contentType - Content type (MIME media type) of the data being stored
475+
* @param path - Path relative to the module root
476+
* @param body - Raw data to store
476477
*
477478
* @returns A promise for the created/updated revision (ETag)
478479
*
@@ -499,9 +500,9 @@ export class BaseClient {
499500
* fileReader.readAsArrayBuffer(file);
500501
* ```
501502
*/
502-
async storeFile (mimeType: string, path: string, body: string | ArrayBuffer | ArrayBufferView): Promise<string> {
503-
if (typeof mimeType !== 'string') {
504-
return Promise.reject('Argument \'mimeType\' of baseClient.storeFile must be a string');
503+
async storeFile (contentType: string, path: string, body: string | ArrayBuffer | ArrayBufferView): Promise<string> {
504+
if (typeof contentType !== 'string') {
505+
return Promise.reject('Argument \'contentType\' of baseClient.storeFile must be a string');
505506
}
506507
if (typeof path !== 'string') {
507508
return Promise.reject('Argument \'path\' of baseClient.storeFile must be a string');
@@ -513,7 +514,7 @@ export class BaseClient {
513514
console.warn('WARNING: Editing a document to which only read access (\'r\') was claimed');
514515
}
515516

516-
return this.storage.put(this.makePath(path), body, mimeType).then((r: QueuedRequestResponse) => {
517+
return this.storage.put(this.makePath(path), body, contentType).then((r: QueuedRequestResponse) => {
517518
if (r.statusCode === 200 || r.statusCode === 201) {
518519
return r.revision;
519520
} else {

0 commit comments

Comments
 (0)