Skip to content
This repository was archived by the owner on Oct 28, 2019. It is now read-only.

Commit 4fe358a

Browse files
authored
Merge pull request #7 from oganexon/develop
v1.0.0-beta
2 parents fdcc8f4 + 97dad78 commit 4fe358a

13 files changed

+2049
-59
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414

1515
## [Unreleased]
1616

17+
## [1.0.0-beta] - 2019-08-16
18+
19+
### Added
20+
- More tests.
21+
22+
### Changed
23+
- Documentation:
24+
- Windows advice.
25+
- Beautified the whole.
26+
1727
## [0.14.0] - 2019-08-15
1828

1929
### Added

CONTRIBUTING.md

+12-19
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ To invoke the command line tool, run:
2121
npm start -- [ARGS]
2222
```
2323

24+
If you want to install all the tools, juste run:
25+
```shell
26+
npm run dev-setup
27+
```
28+
2429
<!--### Deploying / Publishing
2530
give instructions on how to build and release a new version
2631
In case there's some step you have to take that publishes this project to a
@@ -37,35 +42,23 @@ And again you'd need to tell what the previous code actually does.
3742

3843
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [link to tags on this repository](/tags).
3944

40-
<!--## Configuration
41-
42-
Here you should write what are all of the configurations a user can enter when
43-
using the project.
44-
-->
4545

4646
### Tests
4747

48-
> Soon
49-
<!--
50-
Describe and show how to run the tests with code examples.
51-
Explain what these tests test and why.
48+
This project uses the framework [Jest](https://jestjs.io/). Jest is a delightful JavaScript Testing Framework with a focus on simplicity.
5249

53-
```shell
54-
Give an example
55-
```
56-
-->
50+
Simply run `jest` to run the tests.
51+
52+
There are not enough tests, you can add more.
5753

5854
### Style guide
5955

6056
[![JavaScript Style Guide](https://cdn.rawgit.com/standard/standard/master/badge.svg)](https://github.com/standard/standard)
6157

6258
This project uses [JavaScript Standard Style](https://cdn.rawgit.com/standard/standard/master/badge.svg). Please respect this convention.
6359

64-
We provide an easy installation for you, just run:
65-
```shell
66-
$ npm run style-setup
67-
```
60+
You can install a [plugin](https://standardjs.com/awesome.html#editor-plugins) for your favorite editor if you want.
6861

69-
And then `npm run style` each time you want to check style.
62+
### Pull request
7063

71-
Or install a [plugin](https://standardjs.com/awesome.html#editor-plugins) for your favorite editor and ignore the recommandations above.
64+
Please follow the [pull request template](./github/PULL_REQUEST_TEMPLATE/pull_request_template.md).

README.md

+49-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<h1 align="center">
2-
<img src="./assets/secure-rm.png" alt="Logo of the project">
2+
<img src="./assets/secure-rm.png" alt="Secure-rm">
33
<br>
44
Completely erases files by making recovery impossible.
55
<br>
@@ -8,28 +8,35 @@
88
<p align="center">
99
<a href="https://www.npmjs.com/package/secure-rm"><img src="https://img.shields.io/npm/v/secure-rm.svg" alt="Version"></a>
1010
<a href="https://www.npmjs.com/package/secure-rm"><img src="https://img.shields.io/npm/dw/secure-rm.svg" alt="Downloads/week"></a>
11-
<a href="https://github.com/oganexon/secure-rm/blob/master/LICENSE"><img src="https://img.shields.io/npm/l/secure-rm.svg" alt="License"></a>
11+
<a href="https://github.com/oganexon/secure-rm/blob/master/LICENSE"><img src="https://img.shields.io/npm/l/secure-rm.svg" alt="License: MIT"></a>
12+
<a href="https://jestjs.io"><img src="https://img.shields.io/badge/tested_with-jest-99424f.svg" alt="Tested with Jest"></a>
1213
</p>
1314

14-
> v1.0.0 will be released soon, stay tuned!
15+
## ❓ Why
1516

16-
## Install
17+
When you delete a file using the `rm` command or `fs.unlink` in node, it only remove direct pointers to the data disk sectors and make the data recovery possible with common software tools.
18+
19+
Permanent data erasure goes beyond basic file deletion commands, which:
20+
1. Allow for selection of a specific standard, based on unique needs, and
21+
2. Verify the overwriting method has been successful and removed data across the entire device.
22+
23+
## 📦 Install
1724

1825
You can use this package in two different ways, the _npm module version_:
1926

2027
```shell
21-
$ npm install secure-rm --save
28+
npm install secure-rm --save
2229
```
2330

2431
Or the _command-line version_:
2532

2633
```shell
27-
$ npm install secure-rm -g
34+
npm install secure-rm -g
2835
```
2936

3037
Secure-rm will retry 3 times if an error occur to ensure the task succeeded.
3138

32-
## Getting started
39+
## 🚀 Getting started
3340

3441
If you want your application to delete specific files with a pass of cryptographically strong pseudo-random data, use one of these code snippets:
3542

@@ -58,10 +65,10 @@ srm('./folder/*.js')
5865

5966
If you want to delete files on the fly, just use the command line tool:
6067
```shell
61-
$ secure-rm ./folder/*.js
68+
secure-rm ./folder/*.js
6269
```
6370

64-
## Usage
71+
## 📚 Usage
6572

6673
### npm module
6774

@@ -110,7 +117,7 @@ srm('./*', options)
110117
.catch((err) => {throw err})
111118
```
112119
113-
See [write.js](./lib/write.js) file for more details.
120+
If you want to make your own cutom method, see [write.js](./lib/write.js) file for more details.
114121
115122
#### Events
116123
When running, secure-rm emits events to let you know the progression of the deletion.
@@ -130,7 +137,7 @@ srm.event.on('error', (file, err) => console.log('Error ' + err + file))
130137
131138
### Command line tool
132139
```shell
133-
$ secure-rm <PATHS> [OPTIONS]
140+
secure-rm <PATHS> [OPTIONS]
134141
```
135142
- `PATHS`:
136143
- one or multiple paths (e.g. `D:\data /d/data ./data/file.js ../../data`)
@@ -146,7 +153,7 @@ $ secure-rm <PATHS> [OPTIONS]
146153
147154
Example:
148155
```shell
149-
$ secure-rm ./folder/*.js ./garbage ./file.js -m 6 -f
156+
secure-rm ./folder/*.js ./garbage ./file.js -m 6 -f
150157
```
151158
You can invoke the built-in help with `secure-rm -h`:
152159
@@ -155,7 +162,7 @@ You can invoke the built-in help with `secure-rm -h`:
155162
CLI help:
156163
157164
USAGE
158-
$ secure-rm PATH
165+
$ secure-rm PATH
159166
160167
OPTIONS
161168
-f, --force avoid checks
@@ -193,7 +200,24 @@ ID | Name | Passes | Description
193200
194201
Note: Node ensures that the file is correctly written, checking the writing in these algorithms is unnecessary.
195202
196-
## Troubleshooting / Common issues
203+
## 🚩 Troubleshooting / Common issues
204+
205+
Should works on OS X, Linux, and Windows.
206+
207+
### File systems
208+
209+
secure-rm will only work on file systems that overwrite blocks in place.
210+
211+
List of known file systems that will not work:
212+
- ext3
213+
- ext4
214+
- AthFS – AtheOS
215+
- OneFS
216+
- ssd's at large
217+
- reiserfs
218+
- ...
219+
- especially on the vast majority of
220+
journaled file systems.
197221
198222
### "WARN Too many open files, cannot ...:"
199223
@@ -203,18 +227,26 @@ While you don't get an error, the tool can handle this issue.
203227
204228
If you really need to delete millions of file in one time, split the task (e.g. ./your_folder/a* then ./your_folder/b* ...).
205229
206-
## Changelog
230+
### Using Windows:
231+
232+
Be sure to use `secure-rm ".\path\file"` with doublequotes since back-slashes will always be interpreted as escape characters, not path separators.
233+
234+
Another solution is to double the back-slashes like: `secure-rm .\\path\\file`
235+
236+
Or if you can, use forward slashes!
237+
238+
## 📜 Changelog
207239
208240
See the [changelog](/CHANGELOG.md) or [releases](https://github.com/oganexon/secure-rm/releases).
209241
210-
## TODO
242+
## 📌 TODO
211243
212244
- [ ] Release of 1.0.0 (stable API)
213245
- [ ] Implement more tests
214246
- [ ] TypeScript
215247
- [ ] Support of 64bit files
216248
217-
## Contributing
249+
## 🏗 Contributing
218250
219251
See [contributing guidelines](/CONTRIBUTING.md)
220252

bin/cli/check.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ function check (argv, { method, retries, force, globbing }) {
1010
let paths = []
1111
if (globbing) {
1212
for (let i = 0, len = argv.length; i < len; i++) {
13-
if (path.isAbsolute(argv[i])) {
13+
if (path.sep !== '/') {
14+
argv[i] = argv[i].split(path.sep).join('/')
1415
paths = paths.concat(argv[i])
1516
} else {
1617
paths = paths.concat(glob.sync(path.join(process.cwd(), argv[i])))
1718
}
19+
console.log(paths)
1820
}
1921
} else paths = argv
2022
if (paths.length === 0) console.log(chalk.bold.yellow('No such file or directory.'))

lib/methods.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ Pass 32-35: Overwriting with random data.`,
248248
.then(({ fileSize, file }) => write.random(file, fileSize, 4))
249249
.then(({ fileSize, file }) => write.byte(file, 0x55, fileSize))
250250
.then(({ fileSize, file }) => write.byte(file, 0xAA, fileSize))
251-
.then(({ fileSize, file }) => write.cycleByte(file, [0x92, 0x49, 0x24], fileSize))
251+
.then(({ fileSize, file }) => write.cycleBytes(file, [0x92, 0x49, 0x24], fileSize))
252252
.then(({ fileSize, file }) => write.incrementByte(file, { start: 0x00, end: 0xFF, increment: 0x11 }, fileSize))
253253
.then(({ fileSize, file }) => write.cycleByte(file, [0x92, 0x49, 0x24], fileSize))
254254
.then(({ fileSize, file }) => write.cycleByte(file, [0x6D, 0xB6, 0xDB], fileSize))

lib/secure-rm.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function secureRm (path, options, callback) {
99
callback = options
1010
options = { method: 'secure' }
1111
}
12-
if (options.method === undefined) options.method = 'secure'
12+
if (options.method == null) options.method = 'secure'
1313

1414
if (callback) secureRmCallback(path, options, (err, path) => callback(err, path))
1515
else return secureRmPromise(path, options)

lib/write.js

+19-5
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,28 @@ const write = {
7878
})
7979
})
8080
},
81-
cycleByte: (file, dataArray, fileSize, passes) => {
81+
bytes: (file, dataArray, fileSize, passes) => {
82+
return new Promise((resolve, reject) => {
83+
eventEmitter.emit('info', file, `Writing ${dataArray.map(x => '0x' + x.toString(16))} `)
84+
const dataConverted = Uint8Array.from(dataArray)
85+
fs.writeFile(file, Buffer.alloc(fileSize, dataConverted), (err) => {
86+
if (err) reject(err)
87+
else if (passes > 1) {
88+
write.bytes(file, dataArray, fileSize, passes - 1)
89+
.then(() => resolve({ fileSize, file }))
90+
.catch((err) => reject(err))
91+
} else resolve({ fileSize, file })
92+
})
93+
})
94+
},
95+
cycleBytes: (file, dataArray, fileSize, passes = 1) => {
8296
return new Promise((resolve, reject) => {
8397
eventEmitter.emit('info', file, `Writing ${dataArray.map(x => '0x' + x.toString(16))} `)
8498
const dataConverted = Uint8Array.from(dataArray)
8599
fs.writeFile(file, Buffer.alloc(fileSize, dataConverted), (err) => {
86100
if (err) reject(err)
87101
else if (passes < dataArray.length) {
88-
write.cycleByte(file, offset(dataArray, 1), fileSize, passes + 1)
102+
write.cycleBytes(file, offset(dataArray, 1), fileSize, passes + 1)
89103
.then(() => resolve({ fileSize, file }))
90104
.catch((err) => reject(err))
91105
} else resolve({ fileSize, file })
@@ -97,8 +111,8 @@ const write = {
97111
eventEmitter.emit('info', file, `Writing 0x${start.toString(16)} `)
98112
fs.writeFile(file, Buffer.alloc(fileSize, start), (err) => {
99113
if (err) reject(err)
100-
else if (start < end) {
101-
write.incrementByte(file, { start: start + increment, end: end }, fileSize)
114+
else if (start + increment <= end) {
115+
write.incrementByte(file, { start: start + increment, end: end, increment }, fileSize)
102116
.then(() => resolve({ fileSize, file }))
103117
.catch((err) => reject(err))
104118
} else resolve({ fileSize, file })
@@ -139,7 +153,7 @@ const write = {
139153
},
140154
rename: (file, fileSize) => {
141155
return new Promise((resolve, reject) => {
142-
const newName = Math.random().toString(36).substring(2, 15)
156+
const newName = crypto.randomBytes(9).toString('base64').replace(/\//g, '0').replace(/\+/g, 'a')
143157
const newPath = path.join(path.dirname(file), newName)
144158
eventEmitter.emit('info', file, `Renaming to ${newName} `)
145159
fs.rename(file, newPath, (err) => {

0 commit comments

Comments
 (0)