feat(images): can now import and export images, start work on local 100% JS oci imageregistry
This commit is contained in:
40
ts/classes.imagestore.ts
Normal file
40
ts/classes.imagestore.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import * as plugins from './plugins.js';
|
||||
import * as paths from './paths.js';
|
||||
|
||||
export interface IDockerImageStoreConstructorOptions {
|
||||
dirPath: string;
|
||||
}
|
||||
|
||||
export class DockerImageStore {
|
||||
public options: IDockerImageStoreConstructorOptions;
|
||||
|
||||
constructor(optionsArg: IDockerImageStoreConstructorOptions) {
|
||||
this.options = optionsArg;
|
||||
}
|
||||
|
||||
// Method to store tar stream
|
||||
public async storeImage(imageName: string, tarStream: NodeJS.ReadableStream): Promise<void> {
|
||||
const imagePath = plugins.path.join(this.options.dirPath, `${imageName}.tar`);
|
||||
|
||||
// Create a write stream to store the tar file
|
||||
const writeStream = plugins.smartfile.fsStream.createWriteStream(imagePath);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
tarStream.pipe(writeStream);
|
||||
|
||||
writeStream.on('finish', resolve);
|
||||
writeStream.on('error', reject);
|
||||
});
|
||||
}
|
||||
|
||||
// Method to retrieve tar stream
|
||||
public async getImage(imageName: string): Promise<plugins.smartstream.stream.Readable> {
|
||||
const imagePath = plugins.path.join(this.options.dirPath, `${imageName}.tar`);
|
||||
|
||||
if (!(await plugins.smartfile.fs.fileExists(imagePath))) {
|
||||
throw new Error(`Image ${imageName} does not exist.`);
|
||||
}
|
||||
|
||||
return plugins.smartfile.fsStream.createReadStream(imagePath);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user