fix(streaming): Convert smartrequest v5 web ReadableStreams to Node.js streams and update deps for streaming compatibility
This commit is contained in:
@@ -105,6 +105,9 @@ export class DockerImage {
|
||||
optionsArg.tarStream,
|
||||
);
|
||||
|
||||
// requestStreaming now returns Node.js stream
|
||||
const nodeStream = response as plugins.smartstream.stream.Readable;
|
||||
|
||||
/**
|
||||
* Docker typically returns lines like:
|
||||
* {"stream":"Loaded image: myrepo/myimage:latest"}
|
||||
@@ -112,16 +115,16 @@ export class DockerImage {
|
||||
* So we will collect those lines and parse out the final image name.
|
||||
*/
|
||||
let rawOutput = '';
|
||||
response.on('data', (chunk) => {
|
||||
nodeStream.on('data', (chunk) => {
|
||||
rawOutput += chunk.toString();
|
||||
});
|
||||
|
||||
// Wrap the end event in a Promise for easier async/await usage
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
response.on('end', () => {
|
||||
nodeStream.on('end', () => {
|
||||
resolve();
|
||||
});
|
||||
response.on('error', (err) => {
|
||||
nodeStream.on('error', (err) => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
@@ -260,10 +263,8 @@ export class DockerImage {
|
||||
`/images/${encodeURIComponent(this.RepoTags[0])}/get`,
|
||||
);
|
||||
|
||||
// Check if response is a Node.js stream
|
||||
if (!response || typeof response.on !== 'function') {
|
||||
throw new Error('Failed to get streaming response for image export');
|
||||
}
|
||||
// requestStreaming now returns Node.js stream
|
||||
const nodeStream = response as plugins.smartstream.stream.Readable;
|
||||
|
||||
let counter = 0;
|
||||
const webduplexStream = new plugins.smartstream.SmartDuplex({
|
||||
@@ -274,20 +275,20 @@ export class DockerImage {
|
||||
},
|
||||
});
|
||||
|
||||
response.on('data', (chunk) => {
|
||||
nodeStream.on('data', (chunk) => {
|
||||
if (!webduplexStream.write(chunk)) {
|
||||
response.pause();
|
||||
nodeStream.pause();
|
||||
webduplexStream.once('drain', () => {
|
||||
response.resume();
|
||||
nodeStream.resume();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
response.on('end', () => {
|
||||
nodeStream.on('end', () => {
|
||||
webduplexStream.end();
|
||||
});
|
||||
|
||||
response.on('error', (error) => {
|
||||
nodeStream.on('error', (error) => {
|
||||
logger.log('error', `Error during image export: ${error.message}`);
|
||||
webduplexStream.destroy(error);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user