-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lab-remil #6
base: master
Are you sure you want to change the base?
lab-remil #6
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"rules": { | ||
"no-console": "off", | ||
"indent": [ "error", 2 ], | ||
"quotes": [ "error", "single" ], | ||
"semi": ["error", "always"], | ||
"linebreak-style": [ "error", "windows" ], | ||
"comma-dangle": ["error", "always-multiline"] | ||
}, | ||
"env": { | ||
"es6": true, | ||
"node": true, | ||
"mocha": true, | ||
"jasmine": true | ||
}, | ||
"ecmaFeatures": { | ||
"modules": true, | ||
"experimentalObjectRestSpread": true, | ||
"impliedStrict": true | ||
}, | ||
"extends": "eslint:recommended" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
# Created by https://www.gitignore.io/api/node,vim,osx,macos,linux | ||
|
||
*node_modules | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice work ignoring node modules. |
||
|
||
### Node ### | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules | ||
jspm_packages | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
|
||
|
||
### Vim ### | ||
# swap | ||
[._]*.s[a-v][a-z] | ||
[._]*.sw[a-p] | ||
[._]s[a-v][a-z] | ||
[._]sw[a-p] | ||
# session | ||
Session.vim | ||
# temporary | ||
.netrwhist | ||
*~ | ||
# auto-generated tag files | ||
tags | ||
|
||
|
||
### OSX ### | ||
*.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Icon must end with two \r | ||
Icon | ||
# Thumbnails | ||
._* | ||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
.com.apple.timemachine.donotpresent | ||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
|
||
### macOS ### | ||
# Icon must end with two \r | ||
# Thumbnails | ||
# Files that might appear in the root of a volume | ||
# Directories potentially created on remote AFP share | ||
|
||
|
||
### Linux ### | ||
|
||
# temporary files which can be created if a process still has a handle open of a deleted file | ||
.fuse_hidden* | ||
|
||
# KDE directory preferences | ||
.directory | ||
|
||
# Linux trash folder which might appear on any partition or disk | ||
.Trash-* | ||
|
||
# .nfs files are created when an open file is removed but is still being accessed | ||
.nfs* | ||
|
||
# End of https://www.gitignore.io/api/node,vim,osx,macos,linux |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Ain't nothin but a g-thang |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
All hail the redskins!!! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The doppity doppest doptacular dopeness eva | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dope. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
const gulp = require('gulp'); | ||
const eslint = require('gulp-eslint'); | ||
const mocha = require('gulp-mocha'); | ||
|
||
gulp.task('test', function gulpTest(){ | ||
gulp.src('./test/*-test.js', {read: false}) | ||
.pipe(mocha({reporter: 'spec'})); | ||
}); | ||
|
||
gulp.task('lint', function gulpLint(){ | ||
return gulp.src(['**/*.js', '!node_modules/**']) | ||
.pipe(eslint()) | ||
.pipe(eslint.format()) | ||
.pipe(eslint.failAfterError()); | ||
}); | ||
|
||
gulp.task('dev', function gulpDev(){ | ||
gulp.watch(['**/*.js', '!node_modules/**'], ['lint', 'test']); | ||
}); | ||
|
||
gulp.task('default', ['dev']); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice work setting your default gulp task to run all of your other gulp tasks. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
|
||
const fileLogger = require('./lib/filelogger.js'); | ||
|
||
fileLogger([`${__dirname}/data/one.txt`, `${__dirname}/data/two.txt`, `${__dirname}/data/three.txt`], function(err, result) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perfect function here. For readability, I'd recommend in a similar situation, storing these filepaths into an array so you can pass them into this function more cleanly. :) |
||
if(err) throw err; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup. Good. If an error comes from the callback, throw it and stop the function! |
||
console.log(result); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
|
||
module.exports = function fileLogger(files, callback) { | ||
let resultArray = files.map(function(file){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice use of map! Higher order functions ftw! |
||
return { | ||
path: file, | ||
}; | ||
}); | ||
|
||
let filterBufferHex = function(bufferObj) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice job abstracting this into its own function so your code below is nicer to read. |
||
return bufferObj.toString('hex', 0, 8); | ||
}; | ||
|
||
for(let i=0; i < files.length; i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typically you want a space around the = in your first for loop argument. e.g. i = 0 is cleaner and a bit more "conventional". |
||
let readFile = files[i]; | ||
fs.readFile(readFile, function(err, data) { | ||
if (err) return callback(err); | ||
resultArray[files.indexOf(readFile)].result = filterBufferHex(data); | ||
if (resultArray.filter(function(file){ | ||
return Object.keys(file).includes('result'); | ||
}).length === files.length) { | ||
return callback(null, resultArray); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perfect use of the callback here. |
||
} | ||
}); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "lab-remil", | ||
"version": "1.0.0", | ||
"description": "![CF](https://camo.githubusercontent.com/70edab54bba80edb7493cad3135e9606781cbb6b/687474703a2f2f692e696d6775722e636f6d2f377635415363382e706e67) Lab 03: Parallel File Processing\r ===", | ||
"main": "index.js", | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/remilonwheels/03-parallel_file_processing.git" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/remilonwheels/03-parallel_file_processing/issues" | ||
}, | ||
"homepage": "https://github.com/remilonwheels/03-parallel_file_processing#readme", | ||
"dependencies": { | ||
"bluebird": "^3.4.7" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"gulp": "^3.9.1", | ||
"gulp-eslint": "^3.0.1", | ||
"gulp-mocha": "^3.0.1", | ||
"mocha": "^3.2.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
'use strict'; | ||
|
||
const fileLogger = require('../lib/fileLogger.js'); | ||
const expect = require('chai').expect; | ||
|
||
describe('FileLogger Module', function() { | ||
describe('with an improper file path', function(){ | ||
it('should return an error', function(done) { | ||
let badFilePath = 'badfile/sobad'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good test. Sobad. |
||
fileLogger([badFilePath], function(err) { | ||
expect(err).to.be.an('error'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('with one proper file path passed in an array', function() { | ||
let input = [`${__dirname}/../data/one.txt`]; | ||
it('should return an array of the same length as the input array', function(done) { | ||
fileLogger(input , function(err, data) { | ||
expect(err).to.equal(null); | ||
expect(data).to.be.an('array'); | ||
expect(data.length).to.equal(input.length); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool. Yup, our output array's length should be the same. Good length. |
||
done(); | ||
}); | ||
}); | ||
|
||
it('returned array should have a result property that has value of the first 8 bits in hex', function(done) { | ||
fileLogger(input , function(err, data) { | ||
expect(data[0]).to.have.property('result'); | ||
expect(data[0].result.length).to.equal(16); | ||
expect(data[0].result).to.equal('41696e2774206e6f'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('with three files passed in array', function(){ | ||
let input = [`${__dirname}/../data/one.txt`, `${__dirname}/../data/two.txt`, `${__dirname}/../data/three.txt`]; | ||
it('should return an array of the same length as the input array', function(done){ | ||
fileLogger(input, function(err, data) { | ||
expect(err).to.equal(null); | ||
expect(data).to.be.an('array'); | ||
expect(data.length).to.equal(input.length); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('returned array should be in the same order as the input array', function(done){ | ||
fileLogger(input, function(err, data) { | ||
expect(data[0].path).to.equal(input[0]); | ||
expect(data[1].path).to.equal(input[1]); | ||
expect(data[2].path).to.equal(input[2]); | ||
done(); | ||
}); | ||
|
||
let inputDiff = [ `${__dirname}/../data/three.txt`,`${__dirname}/../data/one.txt`, `${__dirname}/../data/two.txt`]; | ||
fileLogger(inputDiff, function(err, data) { | ||
expect(data[0].path).to.equal(input[0]); | ||
expect(data[1].path).to.equal(input[1]); | ||
expect(data[2].path).to.equal(input[2]); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('returned array should have a result property that has value of the first 8 bits in hex', function(done) { | ||
fileLogger(input , function(err, data) { | ||
expect(data[0]).to.have.property('result'); | ||
expect(data[1]).to.have.property('result'); | ||
expect(data[2]).to.have.property('result'); | ||
expect(data[0].result.length).to.equal(16); | ||
expect(data[1].result.length).to.equal(16); | ||
expect(data[2].result.length).to.equal(16); | ||
expect(data[0].result).to.equal('41696e2774206e6f'); | ||
expect(data[1].result).to.equal('54686520646f7070'); | ||
expect(data[2].result).to.equal('416c6c206861696c'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lots of tests. Radical! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
YEAH TEAM COMMA DANGLE! WHOO!