diff --git a/.changeset/funny-snails-cry.md b/.changeset/funny-snails-cry.md new file mode 100644 index 0000000000..161a386a8c --- /dev/null +++ b/.changeset/funny-snails-cry.md @@ -0,0 +1,5 @@ +--- +'@backstage/techdocs-common': patch +--- + +fix to-string breakage of binary files diff --git a/packages/techdocs-common/src/stages/publish/awsS3.ts b/packages/techdocs-common/src/stages/publish/awsS3.ts index 7a21ae6475..3f7a0e3d81 100644 --- a/packages/techdocs-common/src/stages/publish/awsS3.ts +++ b/packages/techdocs-common/src/stages/publish/awsS3.ts @@ -24,13 +24,13 @@ import { PublisherBase, PublishRequest } from './types'; import fs from 'fs-extra'; import { Readable } from 'stream'; -const streamToString = (stream: Readable): Promise => { +const streamToBuffer = (stream: Readable): Promise => { return new Promise((resolve, reject) => { try { const chunks: any[] = []; stream.on('data', chunk => chunks.push(chunk)); stream.on('error', reject); - stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8'))); + stream.on('end', () => resolve(Buffer.concat(chunks))); } catch (e) { throw new Error(`Unable to parse the response data, ${e.message}`); } @@ -173,7 +173,7 @@ export class AwsS3Publish implements PublisherBase { Key: `${entityRootDir}/techdocs_metadata.json`, }) .then(async file => { - const techdocsMetadataJson = await streamToString( + const techdocsMetadataJson = await streamToBuffer( file.Body as Readable, ); @@ -183,7 +183,7 @@ export class AwsS3Publish implements PublisherBase { ); } - resolve(techdocsMetadataJson); + resolve(techdocsMetadataJson.toString('utf-8')); }) .catch(err => { this.logger.error(err.message); @@ -211,7 +211,7 @@ export class AwsS3Publish implements PublisherBase { this.storageClient .getObject({ Bucket: this.bucketName, Key: filePath }) .then(async object => { - const fileContent = await streamToString(object.Body as Readable); + const fileContent = await streamToBuffer(object.Body as Readable); if (!fileContent) { throw new Error(`Unable to parse the file ${filePath}.`); }