Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zoubin/util-equal
Utils for checking file contents
https://github.com/zoubin/util-equal
Last synced: 8 days ago
JSON representation
Utils for checking file contents
- Host: GitHub
- URL: https://github.com/zoubin/util-equal
- Owner: zoubin
- Created: 2015-09-15T08:52:15.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-09-16T03:19:44.000Z (about 9 years ago)
- Last Synced: 2024-08-11T12:32:39.986Z (3 months ago)
- Language: JavaScript
- Size: 141 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# util-equal
Utils for checking file contents.Support four cases:
* Streams v.s. Streams.
* Filenames v.s. filenames.
* Streams v.s. filenames.
* Streams v.s. contents.## Example
```javascript
var equal = require('util-equal');
var fs = require('fs');
var path = require('path');
var filename = path.join(__dirname, 'source');
var expected = path.join(__dirname, 'source.expected');equal(
fs.createReadStream(filename),
fs.createReadStream(expected),
function (res) {
console.log('stream v.s. stream', res);
}
);equal(
filename,
expected,
function (res) {
console.log('filename v.s. filename', res);
}
);equal(
fs.createReadStream(filename),
expected,
function (res) {
console.log('stream v.s. filename', res);
}
);equal.str(
fs.createReadStream(filename),
fs.readFileSync(expected, 'utf8'),
function (res) {
console.log('stream v.s. contents', res);
}
);```
outputs:
```
⌘ node example/equal.js
stream v.s. stream true
filename v.s. filename true
stream v.s. filename true
stream v.s. contents true
```## API
### equal(actual, expected, done)
Check whether file contents are the same.
#### actual, expected
Type: `Stream`, `String`, `Array`
If `Stream`, should flow the file contents.
If `String`, should be the filename.
If `Array`, each element should be `Stream` or `String`.#### done(res)
If contents equal, `res` will be `true`, otherwise `false`.
### equal.str(actual, expected, done)
The only difference from `equal` is that `String` is treated as file contents rather than filename.