Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit 971c157

Browse files
Adding a getJSON method to File as mentioned in #257
1 parent 37b48eb commit 971c157

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/sharepoint/rest/files.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,14 @@ export class File extends QueryableInstance {
295295
return new File(this, "$value").get(new BufferFileParser(), { headers: { "binaryStringResponseBody": "true" } });
296296
}
297297

298+
/**
299+
* Gets the contents of a file as an ArrayBuffer, works in Node.js
300+
*/
301+
public getJSON(): Promise<any> {
302+
303+
return new File(this, "$value").get(new JSONFileParser(), { headers: { "binaryStringResponseBody": "true" } });
304+
}
305+
298306
/**
299307
* Sets the content of a file, for large files use setContentChunked
300308
*
@@ -434,6 +442,13 @@ export class BlobFileParser implements ODataParser<any, Blob> {
434442
}
435443
}
436444

445+
export class JSONFileParser implements ODataParser<any, any> {
446+
447+
public parse(r: Response): Promise<any> {
448+
return r.json();
449+
}
450+
}
451+
437452
export class BufferFileParser implements ODataParser<any, ArrayBuffer> {
438453

439454
public parse(r: any): Promise<ArrayBuffer> {

src/sharepoint/rest/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export {
1414
TextFileParser,
1515
BlobFileParser,
1616
BufferFileParser,
17+
JSONFileParser,
1718
ChunkedFileUploadProgressData
1819
} from "./files";
1920

0 commit comments

Comments
 (0)