in src/plugin/utils/file_storage.ts [177:208]
async save(modelArtifacts: io.ModelArtifacts): Promise<io.SaveResult> {
if (modelArtifacts.modelTopology instanceof ArrayBuffer) {
throw new Error(
'AsyncStorageHandler.save() does not support saving model topology ' +
'in binary format.');
} else {
// We save three items separately for each model,
// a ModelArtifactsInfo, a ModelArtifacts without weights
// and the model weights.
const modelArtifactsInfo = getModelArtifactsInfoForJSON(modelArtifacts);
const {weightData, ...modelArtifactsWithoutWeights} = modelArtifacts;
try {
await mkdir(this.fsm, MODEL_PATH);
await writeFile(
this.fsm, this.paths.info, JSON.stringify(modelArtifactsInfo),
'utf-8');
await writeFile(
this.fsm, this.paths.modelArtifactsWithoutWeights,
JSON.stringify(modelArtifactsWithoutWeights), 'utf-8');
await writeFile(this.fsm, this.paths.weightData, weightData);
return {modelArtifactsInfo};
} catch (err) {
// If saving failed, clean up all items saved so far.
await removeFile(this.fsm, this.paths.info);
await removeFile(this.fsm, this.paths.modelArtifactsWithoutWeights);
await removeFile(this.fsm, this.paths.weightData);
throw new Error(err);
}
}
}