Skip to content

Commit

Permalink
[refactor] updating syntax and doing some light clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel Solano committed Oct 26, 2020
1 parent 05e37f4 commit 224a3d5
Showing 1 changed file with 33 additions and 30 deletions.
63 changes: 33 additions & 30 deletions lib/temp.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
var fs = require('fs'),
path = require('path'),
cnst = require('constants');
let fs = require('fs');
let path = require('path');
let cnst = require('constants');

var rimraf = require('rimraf'),
os = require('os'),
osTmpdir = require('os').tmpdir(),
mkdirp = require('mkdirp'),
rimrafSync = rimraf.sync;
let os = require('os');
let rimraf = require('rimraf');
let mkdirp = require('mkdirp');
let osTmpdir = require('os').tmpdir();

/* HELPERS */
const rimrafSync = rimraf.sync;

var dir = path.resolve(os.tmpdir());
//== helpers
//
let dir = path.resolve(os.tmpdir());

var RDWR_EXCL = cnst.O_CREAT | cnst.O_TRUNC | cnst.O_RDWR | cnst.O_EXCL;
let RDWR_EXCL = cnst.O_CREAT | cnst.O_TRUNC | cnst.O_RDWR | cnst.O_EXCL;

var promisify = function(callback) {
let promisify = function(callback) {
if (typeof callback === 'function') {
return [undefined, callback];
}
Expand Down Expand Up @@ -253,14 +254,14 @@ function cleanup(callback) {
return promise;
}

/* DIRECTORIES */

function mkdir(affixes, callback) {
//== directories
//
const mkdir = (affixes, callback) => {
var p = promisify(callback);
var promise = p[0];
callback = p[1];

var dirPath = generateName(affixes, 'd-');
let dirPath = generateName(affixes, 'd-');
mkdirp(dirPath, 0700, function(err) {
if (!err) {
deleteDirOnExit(dirPath);
Expand All @@ -270,16 +271,16 @@ function mkdir(affixes, callback) {
return promise;
}

function mkdirSync(affixes) {
var dirPath = generateName(affixes, 'd-');
const mkdirSync = (affixes) => {
let dirPath = generateName(affixes, 'd-');
mkdirp.sync(dirPath, 0700);
deleteDirOnExit(dirPath);
return dirPath;
}

/* FILES */

function open(affixes, callback) {
//== files
//
const open = (affixes, callback) => {
var p = promisify(callback);
var promise = p[0];
callback = p[1];
Expand All @@ -294,25 +295,27 @@ function open(affixes, callback) {
return promise;
}

function openSync(affixes) {
var filePath = generateName(affixes, 'f-');
var fd = fs.openSync(filePath, RDWR_EXCL, parseInt('0600', 8));
const openSync = (affixes) => {
const filePath = generateName(affixes, 'f-');
let fd = fs.openSync(filePath, RDWR_EXCL, parseInt('0600', 8));
deleteFileOnExit(filePath);
return {path: filePath, fd: fd};
}

function createWriteStream(affixes) {
var filePath = generateName(affixes, 's-');
var stream = fs.createWriteStream(filePath, {flags: RDWR_EXCL, mode: parseInt('0600', 8)});
const createWriteStream = (affixes) => {
const filePath = generateName(affixes, 's-');
let stream = fs.createWriteStream(filePath, {flags: RDWR_EXCL, mode: parseInt('0600', 8)});
deleteFileOnExit(filePath);
return stream;
}

/* EXPORTS */
// Settings
//== settings
//
exports.dir = dir;
exports.track = track;
// Functions

//== functions
//
exports.mkdir = mkdir;
exports.mkdirSync = mkdirSync;
exports.open = open;
Expand Down

0 comments on commit 224a3d5

Please sign in to comment.