Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function assertEncryptedFile(path, callback) {
try {
// Openssl encrypted files start with Salted
const expectedBytes = Buffer.from('Salted');
const buffer = Buffer.alloc(6);
const fd = fs.openSync(path, 'r');
// Read the first six bytes
fs.readSync(fd, buffer, 0, 6, 0);
fs.closeSync(fd);
// Assert first 6 characters of the file are "Salted"
assert.deepStrictEqual(buffer, expectedBytes, 'The backup file should be encrypted.');
callback();
} catch (err) {
callback(err);
}
}
function output(side: side) {
// make sure the output file exists
if (!side.outputFile) {
side.outputFile = `ts${side.name}.go`;
side.fd = fs.openSync(side.outputFile, 'w');
}
const f = function (s: string) {
fs.writeSync(side.fd!, s);
fs.writeSync(side.fd!, '\n');
};
f(u.computeHeader(false));
f(`
import (
"context"
"encoding/json"
"golang.org/x/tools/internal/jsonrpc2"
errors "golang.org/x/xerrors"
)
`);
const a = side.name[0].toUpperCase() + side.name.substring(1);
function syncFileToBuffer(filepath) {
var descriptor = fs.openSync(filepath, 'r');
var size = fs.fstatSync(descriptor).size;
var bufferSize = Math.min(size, MaxBufferSize);
var buffer = new Buffer(bufferSize);
fs.readSync(descriptor, buffer, 0, bufferSize, 0);
fs.closeSync(descriptor);
return buffer;
}
var BinFile = function(path) {
/**
* File handle.
* @type {number}
* @private
*/
this.fd_ = fs.openSync(path, 'w');
/**
* Current offset into the file.
* @type {number}
* @private
*/
this.offset_ = 0;
};
const getMd5 = (file) => {
const bufferSize = 8192;
const fd = fs.openSync(file, 'r');
const hash = crypto.createHash('md5');
const buffer = Buffer.alloc(bufferSize);
try {
let bytesRead;
do {
bytesRead = fs.readSync(fd, buffer, 0, bufferSize);
hash.update(buffer.slice(0, bytesRead));
} while (bytesRead === bufferSize);
} finally {
fs.closeSync(fd);
}
return hash.digest('hex');
}
function writeFile(file, data) {
try {
const handle = fs.openSync(file, 'w');
fs.writeFileSync(file, data);
fs.closeSync(handle);
return true;
} catch (err) {
return false;
}
}
function write(fileName, content) {
var fd = fs.openSync(path.join(fontRoot, fileName), 'w');
fs.writeSync(fd, content);
fs.closeSync(fd);
}
var sorted = sortKeys(out, {
function copyFileSync(srcFile, destFile) {
var BUF_LENGTH = 64*1024;
var buff = new Buffer(BUF_LENGTH);
var fdr = fs.openSync(srcFile, 'r');
var fdw = fs.openSync(destFile, 'w');
var bytesRead = 1
var pos = 0
while (bytesRead > 0) {
bytesRead = fs.readSync(fdr, buff, 0, BUF_LENGTH, pos);
fs.writeSync(fdw,buff,0,bytesRead);
pos += bytesRead;
}
fs.closeSync(fdr)
fs.closeSync(fdw)
}