res.files.forEach(function(file){
   var wrapped_error = "<div id='roots-error'><span>compile error</span>" + error.toString().replace(/(\r\n|\n|\r)/gm, "<br>") + "</div>" + css;
   fs.writeSync(fs.openSync(file.fullPath, 'a+'), wrapped_error, null, 'utf-8');
 });
Пример #2
0
var stream = temp.createWriteStream('baz');
assert.ok(stream instanceof fs.WriteStream, 'temp.createWriteStream did not invoke the callback with the err and stream object');
stream.write('foo');
stream.end("More text here\nand more...");
assert.ok(existsSync(stream.path), 'temp.createWriteStream did not create a file');

// cleanupSync()
temp.cleanupSync();
assert.ok(!existsSync(stream.path), 'temp.cleanupSync did not remove the createWriteStream file');

// cleanup()
var cleanupFired = false;
// Make a temp file just to cleanup
var tempFile = temp.openSync();
fs.writeSync(tempFile.fd, 'foo');
fs.closeSync(tempFile.fd);
assert.ok(existsSync(tempFile.path), 'temp.openSync did not create a file for cleanup');

// run cleanup()
temp.cleanup(function(err, counts) {
  cleanupFired = true;
  assert.ok(!err, 'temp.cleanup did not run without encountering an error');
  assert.ok(!existsSync(tempFile.path), 'temp.cleanup did not remove the openSync file for cleanup');
  assert.equal(1, counts.files, 'temp.cleanup did not report the correct removal statistics');
});

var tempPath = temp.path();
assert.ok(path.dirname(tempPath) === temp.dir, "temp.path does not work in default os temporary directory");

tempPath = temp.path({dir: process.cwd()});
Пример #3
0
  trade_channel = client.subscribe('live_trades');
  trade_channel.on('success', function () {
    trade_channel.on('trade', function (data, ts) {
      console.log('Trade');
      console.log(ts);
      var trade = { ts: ts, trade: data };
      trades.push(trade);
    });
  });
});

client.connect();

var data_file = fs.openSync('./event.log', 'w');
fs.writeSync(data_file, "[\n");

setInterval(function () {

  var booksByTime = _.groupBy(books, 'ts');
  var tradesByTime = _.groupBy(trades, 'ts');

  var want = {};
  _.union(Object.keys(booksByTime), Object.keys(tradesByTime)).forEach(function(e) {
    want[e] = [];
    if(booksByTime[e]) want[e] = want[e].concat(booksByTime[e])
    if(tradesByTime[e]) want[e] = want[e].concat(tradesByTime[e])
  });

  if(Object.keys(want).length != 0) {
    fs.writeSync(data_file, JSON.stringify(want))
Пример #4
0
    return co(function* () {

      exec(`rsync -crlDvtz -e ssh --delete-after ${config.publicRoot}/task ${config.publicRoot}/article ${host}:${config.publicRoot}/`);


      del.sync('dump');


      exec('mkdir dump');

      /*
      monngoexport/import instead of mongodump => for better debug
      collections.forEach(function(coll) {
        exec('mongoexport --out dump/'+coll+'.json -d js -c ' + coll);
      });

      exec('ssh ' + args.host + ' "rm -rf dump"');
      exec('scp -r -C dump ' + host + ':');

      collections.forEach(function(coll) {
        exec('ssh ' + host + ' "mongoimport --db js_sync --drop --file dump/'+coll+'.json"');
      });*/
      collections.forEach(function(coll) {
        exec('mongodump -d ' + db + ' -c ' + coll);
      });
      exec('mv dump/' + db + ' dump/js_sync');

      exec('ssh ' + args.host + ' "rm -rf dump"');
      exec('scp -r -C dump ' + host + ':');

      exec('ssh ' + host + ' "mongorestore --drop"');



      var file = fs.openSync("/tmp/cmd.js", "w");

      fs.writeFileSync("/tmp/check.sh", 'mongo ' + db + ' --eval "db.articles.find().length()";\n');

      // copy/overwrite collections from js_sync to js and then remove non-existing ids
      // without destroy! (elasticsearch river breaks)
      fs.writeSync(file, collections.map(function(coll) {
        // copyTo does not work
        // also see https://jira.mongodb.org/browse/SERVER-732

        // remove non-existing articles
        // insert (replace) synced ones
        var cmd = `
        db.COLL.find({}, {id:1}).forEach(function(d) {
          var cursor = db.getSiblingDB('js_sync').COLL.find({_id:d._id}, {id:1});

          if (!cursor.hasNext()) {
            db.COLL.remove({_id: d._id});
          }
        });

        db.getSiblingDB('js_sync').COLL.find().forEach(function(d) { db.COLL.update({_id:d._id}, d, { upsert: true}) });
        `.replace(/COLL/g, coll);
        // db.getSiblingDB('js_sync').COLL.find().forEach(function(d) { print(db.COLL.update({_id:d._id}, d, { upsert: true})  ) });


        return cmd;

      }).join("\n\n"));


      fs.closeSync(file);

      exec('scp /tmp/cmd.js ' + host + ':/tmp/');
      exec('scp /tmp/check.sh ' + host + ':/tmp/');

      exec('ssh ' + host + ' "bash /tmp/check.sh"');
      exec('ssh ' + host + ' "mongo ' + db + ' /tmp/cmd.js"');
      exec('ssh ' + host + ' "bash /tmp/check.sh"');

      /* jshint -W106 */
      var env = ecosystem.apps[0]['env_' + args.host];

      exec(`ssh ${host} "cd ${config.projectRoot} && SITE_HOST=${env.SITE_HOST} STATIC_HOST=${env.STATIC_HOST} gulp tutorial:cacheRegenerate && gulp cache:clean"`);
    });
Пример #5
0
var fs = require ('fs');
var veggieTray = ["carrots", "celery", "olives"];
fd = fs.openSync('../data/veggie.txt', 'w');
while (veggieTray.length){
	veggie = veggieTray.pop() + " ";
	var bytes = fs.writeSync(fd, veggie, null, null);
	console.log("Wrote %s %dbytes", veggie, bytes);
}
fs.closeSync(fd);
 __expression_$RNHqj = function(i) {
     var fd = store.register('/Users/Jed/Development/Keystone/lib/content/type.js');
     fs.writeSync(fd, '{"expression": {"node": ' + i + '}},\n');
 }; 
 __statement_s$G4NI = function(i) {
     var fd = store.register('/Users/Jed/Development/Keystone/lib/content/type.js');
     fs.writeSync(fd, '{"statement": {"node": ' + i + '}},\n');
 }; 
Пример #8
0
 }).then(function () {
   fs.writeSync(outFD, JSON.stringify(into) + '\n');
   return true;
 });
Пример #9
0
            }
        }
    }

    src = src.replace(campat_r, '');

    if (config.noES5) {
        src = src.replace(ECMAScript5, '');
    }
    if (config.noltIE9) {
        src = src.replace(ltIE9_r, '');
    }
    src = src.replace(/\/\*\*\//g, '');
    var buf = new Buffer(src);
    // fs.appendFileSync(ajsFile, src.replace(r, ''));
    fs.writeSync(fd, buf, 0, buf.length, null);

    if (m.indexOf('third-party') == -1) {
        if (bootModules.indexOf('#' + m + '#') != -1) {
            fs.appendFileSync(bootFile, src);
        }

        var single = '../dist/' + m + '.js';
        if (fs.existsSync(single)) {
            fs.unlinkSync(single);
        }
        checkdir(single, true);

        if (fs.existsSync(single)) {
            fs.unlinkSync(single);
        }
Пример #10
0
var fs=require("fs"),path=require("path"),less=require("less"),options={compress:!1,optimization:1,silent:!1},allFiles=[].concat(fs.readdirSync("."),fs.readdirSync("form").map(function(a){return"form/"+a}),fs.readdirSync("layout").map(function(a){return"layout/"+a})),lessFiles=allFiles.filter(function(a){return a&&a!="variables.less"&&/\.less$/.test(a)});lessFiles.forEach(function(a){console.log("=== "+a),fs.readFile(a,"utf-8",function(b,c){b&&(console.error("lessc: "+b.message),process.exit(1)),(new less.Parser({paths:[path.dirname(a)],optimization:options.optimization,filename:a})).parse(c,function(b,c){if(b)less.writeError(b,options),process.exit(1);else try{var d=c.toCSS({compress:options.compress}),e=a.replace(".less",".css"),f=fs.openSync(e,"w");fs.writeSync(f,d,0,"utf8")}catch(g){less.writeError(g,options),process.exit(2)}})})})
Пример #11
0
  (function() { // try read
    var atEol, limit,
      isCooked = !options.hideEchoBack && !options.keyIn,
      buffer, reqSize, readSize, chunk, line;

    // Node.js v0.10- returns an error if same mode is set.
    function setRawMode(mode) {
      if (mode === isRawMode) { return true; }
      if (ttyR.setRawMode(mode) !== 0) { return false; }
      isRawMode = mode;
      return true;
    }

    if (_DBG_useExt || !ttyR ||
        typeof fdW !== 'number' && (options.display || !isCooked)) {
      input = tryExt();
      return;
    }

    if (options.display) {
      fs.writeSync(fdW, options.display);
      options.display = '';
    }
    if (options.displayOnly) { return; }

    if (!setRawMode(!isCooked)) {
      input = tryExt();
      return;
    }

    // https://github.com/nodejs/node/issues/4660
    // https://github.com/nodejs/node/pull/4682
    if (Buffer.alloc) {
      buffer = Buffer.alloc((reqSize = options.keyIn ? 1 : options.bufferSize));
    } else {
      buffer = new Buffer((reqSize = options.keyIn ? 1 : options.bufferSize));
    }

    if (options.keyIn && options.limit) {
      limit = new RegExp('[^' + options.limit + ']',
        'g' + (options.caseSensitive ? '' : 'i'));
    }

    while (true) {
      readSize = 0;
      try {
        readSize = fs.readSync(fdR, buffer, 0, reqSize);
      } catch (e) {
        if (e.code !== 'EOF') {
          setRawMode(false);
          input += tryExt();
          return;
        }
      }
      chunk = readSize > 0 ? buffer.toString(options.encoding, 0, readSize) : '\n';

      if (chunk && typeof (line = (chunk.match(/^(.*?)[\r\n]/) || [])[1]) === 'string') {
        chunk = line;
        atEol = true;
      }

      // other ctrl-chars
      if (chunk) { chunk = chunk.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, ''); }
      if (chunk && limit) { chunk = chunk.replace(limit, ''); }

      if (chunk) {
        if (!isCooked) {
          if (!options.hideEchoBack) {
            fs.writeSync(fdW, chunk);
          } else if (options.mask) {
            fs.writeSync(fdW, (new Array(chunk.length + 1)).join(options.mask));
          }
        }
        input += chunk;
      }

      if (!options.keyIn && atEol ||
        options.keyIn && input.length >= reqSize) { break; }
    }

    if (!isCooked && !silent) { fs.writeSync(fdW, '\n'); }
    setRawMode(false);
  })();
Пример #12
0
      if (callee.type != 'Identifier') {
        continue;
      }
      if (callee.name != '$' && callee.name != 'jQuery') {
        continue;
      }
      fixes.push({
        start: identifier.start,
        end: identifier.end + 1,
        contents: 'on(\'' + identifier.name + '\', ',
      });
      return;
    }
  },
};
traverse(ast, jQueryDeprecatedFunctionVisitor);

fixes.sort(function(a, b) { return a.start - b.start; });

// Manually write the results instead of relying on babel-generator.
// babel-generator moves stuff around too much :/
var lastPos = 0;
const fd = fs.openSync(filename, 'w');
for (var i = 0; i < fixes.length; i++) {
  fs.writeSync(fd, buf.slice(lastPos, fixes[i].start));
  fs.writeSync(fd, fixes[i].contents);
  lastPos = fixes[i].end;
}
fs.writeSync(fd, buf.slice(lastPos));
fs.closeSync(fd);
Пример #13
0
 () => fs.writeSync(fd, 'test', 1),
Пример #14
0
 () => fs.writeSync(fd, buf, 0, 1, 1),
Пример #15
0
function dumpToFile(filename, buf) {
  var fd = fs.openSync(filename, 'w')
  fs.writeSync(fd, buf, 0, buf.length)
  fs.closeSync(fd)
}
Пример #16
0
function logToFile(string) {
  string += '\r\n'
  fs.writeSync(logFileHandle, string)
}
Пример #17
0
for(var j=1;j<=100;j++){
	var fd = fs.openSync('hmtl'+j+'.html','w');
    var name = "log-00"+ j +".txt";

var data = "<!DOCTYPE html>"+"\n"+
'<html lang="en">'+"\n"+
'<head>'+"\n"+
	'<meta charset="UTF-8">'+"\n"+
	'<meta http-equiv="refresh" content = "'+ (j/40+1) +'">'+"\n"+ 
	'<title>Test Page</title>'+"\n"+
	
'</head>'+"\n"+
'<body>'+"\n";


	fs.writeSync(fd,data);  	data = "";

	for(var i=j;i>0;i--){
		data += "<input type='text' value = '"+'=?shadowcrypt-977610ce582578c28dd4a1c9135ef175ba39d2238828d2e3b63915000bed4d83?C5kdFyWrFE/CvCjTOro5R5A8QwIovfnxzb8epBI=??='+"'>";
		data += "\n";
	}

	fs.writeSync(fd,data);     data = "";

	data = '<span id="sta"></span>	<span id="res"></span>';

	fs.writeSync(fd,data);     data = "";

	data = "<script>"+"\n"+

Пример #18
0
 writeSync(value) {
   const writeBuffer = value === HIGH ? HIGH_BUF : LOW_BUF;
   fs.writeSync(this._valueFd, writeBuffer, 0, writeBuffer.length, 0);
 }
 __block_dBsx$7 = function(i) {
     var fd = store.register('/Users/Jed/Development/Keystone/lib/content/type.js');
     fs.writeSync(fd, '{"block": ' + i + '},\n');
 }; 
Пример #20
0
#!/usr/bin/env node

/**
 * Small utility to generate binary files for testing purposes.
 */

var fs = require("fs");
var buffer = new Buffer([ 0x97, 0x4A, 0x42, 0x32, 0x0D, 0x0A, 0x1A, 0x0A ]);

var file = fs.openSync("corrupt-id.jbig2", "w");
fs.writeSync(file, buffer, 0, buffer.length, 0);
function dumpMemoryUsageProfile() {
  console.log("Start writing...");

  // Write data table header to file
  fs.writeSync(dataFd, "time\tRSS\theapUsed\theapTotal\n");

  // Fill test buffer string
  for (var i = 0; i < bufferSize; i++) {
    bufferString += 'X';
  }

  // Start timer, save initial memory usage
  startHrTime = process.hrtime();
  if (dumpMemoryUsageIntervalInMs > 0) {
    dumpMemoryUsageInterval = setInterval(dumpMemoryUsage, dumpMemoryUsageIntervalInMs);
  }
  dumpMemoryUsage();
  if (drawMemoryUsageGraphIntervalInMs > 0) {
    drawMemoryUsageGraphInterval = setInterval(drawMemoryUsageGraph, drawMemoryUsageGraphIntervalInMs);
  }

  // Start async operations
  async.whilst(
    function () {
      var currentHrTime = process.hrtime();
  
      return (currentHrTime[0] - startHrTime[0]) < timeLimitInSec;
    },
    function (callback) {
      performOperation(function () {
        myGc();
  
        if (dumpMemoryUsageIntervalInMs === 0) {
          dumpMemoryUsage();
        }
  
        if (pauseBetweenOperationsInMs > 0) {
          setTimeout(callback, pauseBetweenOperationsInMs);
        } else {
          process.nextTick(callback);
        }
      });
    },
    function (error) {
      if (error) throw error;
  
      // All ok
      if (dumpMemoryUsageInterval) {
        clearInterval(dumpMemoryUsageInterval);
      }
      if (drawMemoryUsageGraphInterval) {
        clearInterval(drawMemoryUsageGraphInterval);
      }
      
      fs.close(dataFd, function (error) {
        if (error) throw error;

        console.log("Draw graph...");
        drawMemoryUsageGraph(function () {
          console.log("Done.");
        });
      });
    }
  );
}
Пример #22
0
 Write: function (str) {
     _fs.writeSync(fd, str);
 },
Пример #23
0
var record = function (filename, settings, totalFrames){
  var fd = fs.openSync (filename, "w");
  var video = omxcam.video (settings);
  
  settings = video.settings ();
  
  var planes = omxcam.yuvPlanes (settings.width, settings.height);
  var planesSlice = omxcam.yuvPlanesSlice (settings.width);
  var frameSize = planes.offsetV + planes.lengthV;
  
  video.start ();
  
  var buffer;
  var slice;
  var yBuffers = [];
  var uBuffers = [];
  var vBuffers = [];
  var current = 0;
  var frames = 0;
  
  while (true){
    buffer = video.read ();
    current += buffer.length;
    
    slice = new Buffer (planesSlice.lengthY);
    buffer.copy (slice, 0, planesSlice.offsetY,
        planesSlice.offsetY + planesSlice.lengthY);
    yBuffers.push (slice);
    
    slice = new Buffer (planesSlice.lengthU);
    buffer.copy (slice, 0, planesSlice.offsetU,
        planesSlice.offsetU + planesSlice.lengthU);
    uBuffers.push (slice);
    
    slice = new Buffer (planesSlice.lengthV);
    buffer.copy (slice, 0, planesSlice.offsetV,
        planesSlice.offsetV + planesSlice.lengthV);
    vBuffers.push (slice);
    
    if (current === frameSize){
      //An entire YUV frame has been received
      current = 0;
      
      buffer = Buffer.concat (yBuffers, planes.lengthY);
      yBuffers.length = 0;
      fs.writeSync (fd, buffer, 0, buffer.length, null);
      
      buffer = Buffer.concat (uBuffers, planes.lengthU);
      uBuffers.length = 0;
      fs.writeSync (fd, buffer, 0, buffer.length, null);
      
      buffer = Buffer.concat (vBuffers, planes.lengthV);
      vBuffers.length = 0;
      fs.writeSync (fd, buffer, 0, buffer.length, null);
      
      if (++frames === totalFrames) break;
    }
  }
  
  video.stop ();
  fs.closeSync (fd);
};
Пример #24
0
 WriteLine: function (str) {
     _fs.writeSync(fd, str + '\r\n');
 },
	if (description)
	{
	    console.log(util.format(", description: %s"));
	}
	console.log("");

	var suffix = content_type_suffixes[content_type]
	var output_file_name = util.format("%s-%d.%s", object_key, object_id,
					   suffix);
	console.log(output_file_name);

	var odata = object_descriptor.GetData();
	console.log("odata length is " + odata.length);
	// console.log(util.inspect(odata));

	fd = fs.openSync(output_file_name, 'w');
	fs.writeSync(fd, new Buffer(odata), 0, odata.length);
	fs.closeSync(fd);

        object_descriptor = get_object_response.NextObject();
    }
}
catch(e)
{
    console.log("Exception: " + e);
}
finally
{
    session.Logout();
}
Пример #26
0
 self.taskList.tasks.forEach(function(task) {
     fs.writeSync(fd, task.rawData);
 });
Пример #27
0
 print: function(message){
     fs.writeSync(1, message + "\n");
 },
Пример #28
0
var filename = __filename;
var fs = require('fs');
var path = require('path');
if(process.argv[2] === '-large') {
    var tmpDir = require("../../../../test/common.js").tmpDir;
    filename = path.join(tmpDir, 'fs-leak1.txt');
    print('building large content...');
    var content;
    for (var i = 0; i < 1024 * 1024; i++) {
        content += 'hello worldçoié\uD83D\uDC4D\n';
    }
    print('done building content');
    var fd = fs.openSync(filename, 'w+');
    var buff = new Buffer(content);
    fs.writeSync(fd, buff, 0, buff.length, 0)
    process.on('exit', function() {
        require('fs').unlinkSync(filename);
    })
}

var perf = require("../perf/common-perf");

perf.startPerf(readFile, 100);

function readFile() {
    perf.actionStart();
    fs.readFile(filename, then);

    function then(er, data) {
        if (perf.canContinue()) {
Пример #29
0
setTimeout(function () {
  fs.writeSync(data_file, ']\n');
  fs.closeSync(data_file);
  process.exit(0);
}, 5*60000);
Пример #30
0
function writeLogLine() {
    fs.writeSync(logFd, "[" + (new Date()).toLocaleString() + "][" + console.outputModule + "] " + Array.prototype.slice.call(arguments).toString() + "\n");
}