Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 0.70 KB | None | 0 0
  1. app.post('/api/blk/pedazosDeInfo',(req,res) => {
  2.     ruta = req.body.ruta;
  3.     informacion = req.body.informacion;
  4.     offset = parseInt( req.body.offset );
  5.    
  6.     ruta = _path.join(__dirname, '..','..' ,ruta);
  7.     buffer = new Buffer(informacion);
  8.  
  9.     fsExtra.ensureFile(ruta, err => {// A: file has now been created, including the directory it is to be placed in
  10.         if (err) console.log(err) // => null
  11.        
  12.         fs.open(ruta, 'r+', function(err, fd) {
  13.             if (err) {
  14.                 throw 'error opening file: ' + err;
  15.             }
  16.             fs.write(fd, buffer, 0, buffer.length, offset, function(err) {
  17.                 if (err) throw 'error writing file: ' + err;
  18.                 fs.close(fd, function() {
  19.                     res.send('file written');
  20.                 })
  21.             });
  22.         });
  23.     })
  24. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement