Merge pull request #18385 from backstage/blam/zlib-failure

[reading] Fix `unexpected end of file`
This commit is contained in:
Ben Lambert
2023-06-24 13:10:39 +02:00
committed by GitHub
9 changed files with 12 additions and 9 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-common': patch
---
use `Readable.from` to explicitly convert the `buffer` from `node-fetch` to a `Readable` stream
@@ -158,7 +158,7 @@ export class AzureUrlReader implements UrlReader {
}
return await this.deps.treeResponseFactory.fromZipArchive({
stream: archiveAzureResponse.body as unknown as Readable,
stream: Readable.from(archiveAzureResponse.body),
etag: commitSha,
filter,
subpath,
@@ -160,7 +160,7 @@ export class BitbucketCloudUrlReader implements UrlReader {
}
return await this.deps.treeResponseFactory.fromTarArchive({
stream: archiveResponse.body as unknown as Readable,
stream: Readable.from(archiveResponse.body),
subpath: filepath,
etag: lastCommitShortHash,
filter: options?.filter,
@@ -151,7 +151,7 @@ export class BitbucketServerUrlReader implements UrlReader {
}
return await this.deps.treeResponseFactory.fromTarArchive({
stream: archiveResponse.body as unknown as Readable,
stream: Readable.from(archiveResponse.body),
subpath: filepath,
etag: lastCommitShortHash,
filter: options?.filter,
@@ -171,7 +171,7 @@ export class BitbucketUrlReader implements UrlReader {
}
return await this.deps.treeResponseFactory.fromTarArchive({
stream: archiveBitbucketResponse.body as unknown as Readable,
stream: Readable.from(archiveBitbucketResponse.body),
subpath: filepath,
etag: lastCommitShortHash,
filter: options?.filter,
@@ -204,7 +204,7 @@ export class GerritUrlReader implements UrlReader {
});
const tarArchive = Readable.from(data);
return await this.deps.treeResponseFactory.fromTarArchive({
stream: tarArchive as unknown as Readable,
stream: tarArchive,
subpath: filePath === '/' ? undefined : filePath,
etag: branchInfo.revision,
filter: options?.filter,
@@ -238,7 +238,7 @@ export class GithubUrlReader implements UrlReader {
return await this.deps.treeResponseFactory.fromTarArchive({
// TODO(Rugvip): Underlying implementation of fetch will be node-fetch, we probably want
// to stick to using that in exclusively backend code.
stream: archive.body as unknown as Readable,
stream: Readable.from(archive.body),
subpath,
etag: sha,
filter: options?.filter,
@@ -347,7 +347,6 @@ export class GithubUrlReader implements UrlReader {
init: RequestInit,
): Promise<Response> {
const urlAsString = url.toString();
const response = await fetch(urlAsString, init);
if (!response.ok) {
@@ -229,7 +229,7 @@ export class GitlabUrlReader implements UrlReader {
}
return await this.deps.treeResponseFactory.fromTarArchive({
stream: archiveGitLabResponse.body as unknown as Readable,
stream: Readable.from(archiveGitLabResponse.body),
subpath: filepath,
etag: commitSha,
filter: options?.filter,
@@ -151,7 +151,6 @@ export class TarArchiveResponse implements ReadTreeResponse {
const strip = this.subPath ? this.subPath.split('/').length : 1;
let filterError: Error | undefined = undefined;
await pipeline(
this.stream,
tar.extract({