0

Can someone help with this problem, I know that there are a lot of questions related to this problem but I have tried almost everything, nothing helps.

makeFile(dirName, fileName, content, callback) {
        if (!fs.existsSync(dirName)) {
            // fs.mkdirSync(dirName, {recursive: true});
            shell.mkdir('-p', dirName);
        }
        zlib.inflate(Buffer.from(content), (err, InfoInflated) => {
            if (err) {
                logger.error(err);
                return callback({ success: false, code: 500, err: err});
            }
let file = fs.createWriteStream(dirName + fileName, {
                    flags: 'a'
                });
            file.on('open', fd => {
                file.write(InfoInflated.toString('utf8'));
                file.end();
            }).on('error' , (err) => {
                logger.error(err);
                return callback({ success: false, code: 500, err: err});
            }).on('finish', () => {
                logger.info("file is complete !");
                return callback({success: true, code: 200, result: {message: "OK", file: dirName + fileName}});
            });
        });
    }

/tmp/files/2019-02-05/1205_undefined_undefined/1205_undefined_undefined.zip' this is the full path which creates an error

6
  • Please add some description about what you are doing and what is failing for the purpose of better understanding. Commented Feb 5, 2019 at 12:43
  • fs.createWriteStream(dirName + fileName, ... - please edit your post and show us the values of dirName and fileName. Also show us where exactly in your code the error gets raised. Commented Feb 5, 2019 at 12:45
  • @Corion I have edited the question Commented Feb 5, 2019 at 12:52
  • @Ashvin777 I have edited the question Commented Feb 5, 2019 at 12:53
  • Again, how do you call the makeFile function? Please show us a minimal reproducible example so we can try to replicate your situation. The value of dirName and fileName are likely important, as is whether the directories you have in dirName already exist. If they don't all exist, createWriteStream will fail with ENOENT (which is file or directory not found). Commented Feb 5, 2019 at 12:58

1 Answer 1

0

I think you are using shell syntax incorrectly. Also you may not need to use shell for creating the directory as it can be done using fs component itself.

Take a look at the solution for your script - https://jsitor.com/fh3IyKq74

It is executing you code and also showing the response properly. In mkdir make sure you should check empty string first actually firing that.

Sign up to request clarification or add additional context in comments.

3 Comments

I have used fs sytem but , it did not help, if you have suggestion I will be glad to see it :)
If you want more details you can take help from this ticket as well - stackoverflow.com/questions/13696148/…
Is this the error you are talking about (node:98) [DEP0025] DeprecationWarning: sys is deprecated. Use util instead. { success: false, code: 500, err: { Error: incorrect header check at Zlib.zlibOnError [as onerror] (zlib.js:155:17) errno: -3, code: 'Z_DATA_ERROR' } }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.