I’m stuck at this error for a bit, i’m unable to save this piece in my system what am i doing wrong?
my code snippet for saving a piece
const fixLinuxPath = (location) => {
if (location.startsWith('/tmp')) {
// Replace with Windows temp directory
return location.replace('/tmp', os.tmpdir());
}
return location;
};
const savePiece = (index, fullPiece, location) => {
location = fixLinuxPath(location); // Ensure location is compatible with Windows
console.log(`Saving piece to: ${location}`);
const pieceFile = path.join(location, `piece-${index}`);
console.log(pieceFile);
// Create the directory if it doesn't exist
fs.mkdir(path.dirname(pieceFile), { recursive: true }, (err) => {
if (err) {
console.error(`Error creating directory: ${err}`);
return;
}
// Save the piece
fs.writeFile(pieceFile, fullPiece, (err) => {
if (err) {
console.error(`Error saving piece ${index}:`, err);
} else {
console.log(`Piece ${index} saved to ${pieceFile}`);
}
});
});
};