How to copy a image?

前端 未结 2 1958
小鲜肉
小鲜肉 2021-02-10 13:48

I want to copy image.png form /folder1 to /folder2, how to do it?

/folder1
  image.png
/folder2

Thanks!<

相关标签:
2条回答
  • 2021-02-10 14:23

    Or if you prefer callbacks:

    fs = require('fs')
    fs.readFile('folder1/image.png', function (err, data) {
        if (err) throw err;
        fs.writeFile('folder2/image.png', data, function (err) {
            if (err) throw err;
            console.log('It\'s saved!');
        });
    });
    
    0 讨论(0)
  • 2021-02-10 14:27

    Try something like this:

    var fs = require('fs');
    
    var inStr = fs.createReadStream('/your/path/to/file');
    var outStr = fs.createWriteStream('/your/path/to/destination');
    
    inStr.pipe(outStr);
    

    Code is not tested, just written down from memory.

    0 讨论(0)
提交回复
热议问题