I have a task where the users inputs a catalog name and image name and based on this the provided file needs to be moved from the provided catalog to the 'temp' file.
This needs to be done with streams as well as the yauzl package since the file is zipped. If someone could help with why the error is appearing as well as helping out with how to implement yauzl here I would be grateful!
I have the below code:
import fs, { createReadStream } from "fs";
import inquirer from "inquirer";
import terminalKit from "terminal-kit";
import yauzl from "yauzl";
inquirer
.prompt([
{
type: "input",
name: "catalog_name",
message: "Enter catalog name:",
},
{
type: "input",
name: "image_name",
message: "Enter image name:",
},
])
.then((answers) => {
const catalogName = answers.catalog_name;
const imageName = answers.image_name;
const filePath = `./${catalogName}/${imageName}`;
if (!fs.existsSync(`./${catalogName}`)) {
throw new Error("Catalog does not exist!");
}
if (fs.existsSync(catalogName)) {
fs.readdir(catalogName, (err, files) => {
const fileDirectoryArr = files;
if (fileDirectoryArr.includes(imageName)) {
const readStream = createReadStream("./images");
const writeStream = fs.createWriteStream("./temp");
readStream.pipe(writeStream);
} else {
throw new Error("Image does not exist!");
}
});
}
})
.catch((error) => {
console.log("Something went wrong!", error);
});
Unfortunately when running the code I get the below error:
node:events:491
throw er; // Unhandled 'error' event
^
Error: EISDIR: illegal operation on a directory, open 'C:\Users\jkuki\Desktop\ONL_FSF_E_16_Egzamin_1\01_Strumienie\temp'
Emitted 'error' event on WriteStream instance at:
at WriteStream.onerror (node:internal/streams/readable:773:14)
at WriteStream.emit (node:events:513:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -4068,
code: 'EISDIR',
syscall: 'open',
path: 'C:\\Users\\jkuki\\Desktop\\ONL_FSF_E_16_Egzamin_1\\01_Strumienie\\temp'
}
Just in case, the directory that I have is as shown below: