Skip to content

Commit

Permalink
feat(fs): when writing json default to contentType of application/json
Browse files Browse the repository at this point in the history
  • Loading branch information
blacha committed Sep 15, 2021
1 parent b0825a3 commit 73947fe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export interface FileInfo {

export interface WriteOptions {
/** Encoding of the file eg "gzip" */
contentEncoding: string;
contentEncoding?: string;
/** Content type of the file eg "text/plain" */
contentType: string;
contentType?: string;
}

export interface FileSystem<T extends ChunkSource = ChunkSource> {
Expand Down
3 changes: 2 additions & 1 deletion packages/fs/src/fs.abstraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ export class FileSystemAbstraction {
*/
write(filePath: string, buffer: FileWriteTypes, opts?: WriteOptions): Promise<void> {
if (Array.isArray(buffer) || isRecord(buffer)) {
return this.get(filePath).write(filePath, JSON.stringify(buffer, null, 2), opts);
const content = JSON.stringify(buffer, null, 2);
return this.get(filePath).write(filePath, content, { contentType: 'application/json', ...opts });
}
return this.get(filePath).write(filePath, buffer, opts);
}
Expand Down

0 comments on commit 73947fe

Please sign in to comment.