From 73947fe7c7d95aa1df00c9ccf72d5c3339e7f1f2 Mon Sep 17 00:00:00 2001 From: Blayne Chard Date: Wed, 15 Sep 2021 18:48:52 +1200 Subject: [PATCH] feat(fs): when writing json default to contentType of application/json --- packages/core/src/fs.ts | 4 ++-- packages/fs/src/fs.abstraction.ts | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/core/src/fs.ts b/packages/core/src/fs.ts index f35de047..e918195c 100644 --- a/packages/core/src/fs.ts +++ b/packages/core/src/fs.ts @@ -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 { diff --git a/packages/fs/src/fs.abstraction.ts b/packages/fs/src/fs.abstraction.ts index 5fe977cd..8689ded0 100644 --- a/packages/fs/src/fs.abstraction.ts +++ b/packages/fs/src/fs.abstraction.ts @@ -77,7 +77,8 @@ export class FileSystemAbstraction { */ write(filePath: string, buffer: FileWriteTypes, opts?: WriteOptions): Promise { 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); }