chore: body is not a buffer, let's make it a Readable first

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2023-06-22 12:39:46 +02:00
parent 126e862ece
commit e65ad09894
8 changed files with 10 additions and 9 deletions
@@ -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: Readable.from(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,9 @@ export class TarArchiveResponse implements ReadTreeResponse {
const strip = this.subPath ? this.subPath.split('/').length : 1;
let filterError: Error | undefined = undefined;
this.stream.on('error', console.error);
this.stream.on('close', console.error);
console.log('we are here!');
await pipeline(
this.stream,
tar.extract({