shredfile
Advanced tools
Comparing version 1.0.1 to 1.1.0
17
index.js
@@ -154,3 +154,3 @@ // Module dependencies. | ||
// eslint-disable-next-line no-async-promise-executor, consistent-return | ||
return new Promise(async (resolve, reject) => { | ||
return new Promise((resolve, reject) => { | ||
const origFiles = files; | ||
@@ -167,2 +167,5 @@ if (typeof files === 'string') files = [files]; | ||
// Current Working Directory for the spawned process | ||
let cwd; | ||
// For storing file name being actively shredded | ||
@@ -174,5 +177,12 @@ let file = path.basename(files[0]); | ||
// If all files have the same path, set the CWD for `spawn` and de-dupe the repeated directories | ||
// so we can help prevent going over the Unix command + args size limit | ||
if (Array.from(new Set(files.map((f) => path.dirname(f)))).length === 1) { | ||
files = files.map((f) => path.basename(f)); | ||
cwd = activeFilePath; | ||
} | ||
// Spawn the shred binary | ||
const options = Array.from(new Set(this.shredFlags.concat(files))); | ||
const shred = spawn(this.settings.shredPath, options); | ||
const shred = spawn(this.settings.shredPath, options, { cwd }); | ||
if (this.settings.debugMode === true) | ||
@@ -203,5 +213,6 @@ console.log(`shredfile: Configured shred command: ${this.settings.shredPath} ${options.join(' ')}`); | ||
if (validInfo.test(data)) { | ||
let matches = data.match(/(\/[^:]+): pass (\d+)\/(\d+)/); | ||
let matches = data.match(/^[^:]+: ([^:]+): pass (\d+)\/(\d+)/); | ||
if (matches !== -1 && matches !== null) { | ||
activeFilePath = path.dirname(matches[1]); | ||
if (activeFilePath === '.' && cwd) activeFilePath = cwd || '.'; | ||
file = path.basename(matches[1]); | ||
@@ -208,0 +219,0 @@ const numerator = parseInt(matches[2], 10); |
{ | ||
"name": "shredfile", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "A simple wrapper to the Unix shred command.", | ||
@@ -16,3 +16,2 @@ "main": "index.js", | ||
}, | ||
"dependencies": {}, | ||
"keywords": [ | ||
@@ -56,6 +55,6 @@ "shred", | ||
"eslint-config-airbnb-base": "^14.2.0", | ||
"eslint-config-prettier": "^6.12.0", | ||
"eslint-config-prettier": "^8.1.0", | ||
"eslint-plugin-chai-friendly": "^0.6.0", | ||
"eslint-plugin-import": "^2.22.1", | ||
"eslint-plugin-jsdoc": "^30.6.3", | ||
"eslint-plugin-jsdoc": "^32.2.0", | ||
"eslint-plugin-prettier": "^3.1.4", | ||
@@ -62,0 +61,0 @@ "husky": "^4.3.0", |
@@ -85,3 +85,3 @@ [![NPM Version][npm-version-image]][npm-url] [![NPM Downloads][npm-downloads-image]][npm-url] [![Node.js Version][node-image]][node-url] [![Build Status][travis-image]][travis-url] | ||
* `file` (string) File name of the file that is currently being acted upon | ||
* `active_file_path` (string) Full path to the file that is currently being acted upon* | ||
* `activeFilePath` (string) Full path to the file that is currently being acted upon (does not include file name) | ||
* `endCb` (function) Will be called when the shred is complete. It takes 2 parameters: | ||
@@ -88,0 +88,0 @@ * `err` (string or null) A standard error message string (null if no error) |
// const fs = require('fs'); | ||
const { statSync, appendFileSync, openSync, existsSync } = require('fs'); | ||
const { statSync, appendFileSync, openSync, existsSync, mkdirSync, rmdirSync } = require('fs'); | ||
const { dirname } = require('path'); | ||
const { describe, it, beforeEach } = require('mocha'); | ||
@@ -13,2 +14,3 @@ const chai = require('chai'); | ||
const testFile2 = './tests/testFile2.txt'; | ||
const testFile3 = './tests/sub/testFile3.txt'; | ||
@@ -18,2 +20,6 @@ chai.use(chaiAsPromised); | ||
const createTestFile = (fileSize, testFile) => { | ||
// Make sure the file path exists | ||
const dir = dirname(testFile); | ||
mkdirSync(dir, { recursive: true }); | ||
// Make a file to shred... | ||
@@ -122,3 +128,3 @@ const ws = openSync(testFile, 'a'); | ||
describe('buildClamFlags', () => { | ||
describe('buildShredFlags()', () => { | ||
let shredder; | ||
@@ -148,3 +154,3 @@ beforeEach(async () => { | ||
describe('buildClamFlags', () => { | ||
describe('shred()', () => { | ||
let shredder; | ||
@@ -172,3 +178,3 @@ beforeEach(async () => { | ||
it('should shred a set of files successfully...', async () => { | ||
it('should shred a set of files in the same directory successfully...', async () => { | ||
// Create 10 MB test file... | ||
@@ -197,2 +203,28 @@ createTestFile(1024 ** 2 * 10, testFile1); | ||
it('should shred a set of files in different directories successfully...', async () => { | ||
// Create 10 MB test file... | ||
createTestFile(1024 ** 2 * 10, testFile1); | ||
// Create 15 MB test file... | ||
createTestFile(1024 ** 2 * 15, testFile3); | ||
// See if files exist... | ||
let file1Exists = existsSync(testFile1); | ||
let file3exists = existsSync(testFile3); | ||
expect(file1Exists).to.be.true; | ||
expect(file3exists).to.be.true; | ||
// Shred those files file... | ||
const files = await shredder.shred([testFile1, testFile3]); | ||
file1Exists = existsSync(testFile1); | ||
file3exists = existsSync(testFile3); | ||
// Make sure all is bueno... | ||
expect(file1Exists).to.be.false; | ||
expect(file3exists).to.be.false; | ||
expect(files).to.be.eql([testFile1, testFile3]); | ||
rmdirSync('./tests/sub'); | ||
}); | ||
it('should shred a file and send status of the shred while doing it...', async () => { | ||
@@ -217,8 +249,8 @@ // Create 10 MB test file... | ||
expect(statusMsgs).to.be.eql([ | ||
'overwriting /tests/testFile.txt: 25%', | ||
'overwriting /tests/testFile.txt: 50%', | ||
'overwriting /tests/testFile.txt: 75%', | ||
'overwriting /tests/testFile.txt: 100%', | ||
'overwriting ./tests/testFile.txt: 25%', | ||
'overwriting ./tests/testFile.txt: 50%', | ||
'overwriting ./tests/testFile.txt: 75%', | ||
'overwriting ./tests/testFile.txt: 100%', | ||
]); | ||
}); | ||
}); |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
35191
479
5