diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..8dc6807 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,21 @@ +{ + "rules": { + "no-console": "off", + "indent": [ "error", 2 ], + "quotes": [ "error", "single" ], + "semi": ["error", "always"], + "linebreak-style": [ "error", "unix" ] + }, + "env": { + "es6": true, + "node": true, + "mocha": true, + "jasmine": true + }, + "ecmaFeatures": { + "modules": true, + "experimentalObjectRestSpread": true, + "impliedStrict": true + }, + "extends": "eslint:recommended" +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b97253f --- /dev/null +++ b/.gitignore @@ -0,0 +1,114 @@ + +# Created by https://www.gitignore.io/api/node,macos,windows + +### macOS ### +*.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 + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.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 + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Typescript v1 declaration files +typings/ + +# 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 + +# dotenv environment variables file +.env + + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.gitignore.io/api/node,macos,windows diff --git a/data/one.txt b/data/one.txt new file mode 100644 index 0000000..2817955 --- /dev/null +++ b/data/one.txt @@ -0,0 +1,3 @@ +Enamel pin fashion axe cred, offal tilde paleo glossier art party unicorn narwhal chicharrones church-key hexagon small batch. Photo booth helvetica quinoa, thundercats lumbersexual deep v mixtape pour-over single-origin coffee whatever. Fam scenester edison bulb farm-to-table, cornhole kinfolk seitan pabst 90's kombucha la croix normcore activated charcoal mumblecore. Polaroid before they sold out 8-bit, etsy pitchfork man bun normcore succulents knausgaard humblebrag franzen kitsch marfa organic actually. Franzen knausgaard kinfolk etsy ugh. Bitters roof party tumblr hammock. Gochujang kinfolk pickled enamel pin jean shorts. + +Enamel pin cold-pressed hoodie, kale chips VHS man braid flexitarian quinoa unicorn pinterest taxidermy vinyl. Echo park tumblr brooklyn, craft beer wayfarers skateboard pug. Forage glossier single-origin coffee kitsch, bicycle rights messenger bag hella chicharrones shabby chic. Tumblr williamsburg truffaut master cleanse unicorn, kickstarter snackwave lo-fi vinyl DIY gentrify photo booth. Umami health goth yuccie, asymmetrical pinterest food truck chartreuse cardigan aesthetic. Drinking vinegar fixie pork belly beard twee, knausgaard hammock typewriter paleo. Microdosing truffaut tofu shabby chic normcore food truck. diff --git a/data/three.txt b/data/three.txt new file mode 100644 index 0000000..3708a3d --- /dev/null +++ b/data/three.txt @@ -0,0 +1,2 @@ +Succulents schlitz skateboard asymmetrical trust fund fingerstache. Pug fingerstache taxidermy, slow-carb meggings messenger bag unicorn subway tile. Hashtag hoodie cornhole quinoa wolf yuccie polaroid, man bun cronut dreamcatcher slow-carb small batch man braid. Sriracha kinfolk whatever, slow-carb gluten-free la croix swag. Copper mug edison bulb tofu aesthetic bespoke try-hard cold-pressed. Direct trade lo-fi small batch, lumbersexual venmo cray ethical post-ironic pork belly lomo poutine tilde try-hard craft beer twee. Dreamcatcher bespoke organic, occupy put a bird on it tumeric literally. + diff --git a/data/two.txt b/data/two.txt new file mode 100644 index 0000000..e35bf6e --- /dev/null +++ b/data/two.txt @@ -0,0 +1,3 @@ +Slow-carb post-ironic la croix, direct trade cray umami irony ugh woke kogi hella. Pickled messenger bag twee, pour-over before they sold out jianbing tbh mustache man braid master cleanse. Leggings wolf man braid heirloom, neutra celiac 8-bit sustainable gastropub tilde glossier four dollar toast you probably haven't heard of them tousled. Banh mi ethical live-edge, trust fund schlitz echo park hot chicken vexillologist. Hot chicken shoreditch live-edge, hexagon tilde twee small batch. Etsy post-ironic pitchfork, kinfolk gastropub chartreuse cred prism humblebrag. Asymmetrical lumbersexual iPhone food truck, 3 wolf moon skateboard cold-pressed slow-carb mixtape biodiesel vaporware cornhole health goth. + +Seitan williamsburg literally, raw denim pork belly wolf hoodie tote bag hammock skateboard. Tumeric subway tile ugh la croix 3 wolf moon. Meh slow-carb af, bushwick church-key tilde kitsch offal swag four loko deep v. Fap scenester portland, chambray forage craft beer deep v sriracha occupy fam affogato. Twee tumblr post-ironic distillery, trust fund freegan mustache YOLO church-key cray unicorn. Pinterest slow-carb banjo 90's. Everyday carry single-origin coffee intelligentsia, mlkshk unicorn aesthetic forage lomo cronut chillwave la croix. diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..9ae97d6 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,23 @@ +'use strict'; + +const gulp = require('gulp'); +const eslint = require('gulp-eslint'); +const mocha = require('gulp-mocha'); + +gulp.task('lint', function() { + return gulp.src(['**/*.js', '!node_modules']) + .pipe(eslint()) + .pipe(eslint.format()) + .pipe(eslint.failAfterError()); +}); + +gulp.task('test', function() { + gulp.src('./test/*-test.js', { read: false }) + .pipe(mocha({ reporter: 'spec'})); +}); + +gulp.task('dev', function() { + gulp.watch(['**/*.js', '!node_modules'], ['lint', 'test']); +}); + +gulp.task('default', ['lint', 'test']); \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..536c891 --- /dev/null +++ b/index.js @@ -0,0 +1,8 @@ +'use strict'; + +const reader = require('./lib/file-reader.js'); + +reader(['one.txt', 'two.txt', 'three.txt'], function(err, data) { + if (err) console.error(err); + console.log('index.js', data); +}); diff --git a/lib/dir-reader.js b/lib/dir-reader.js new file mode 100644 index 0000000..73dc16d --- /dev/null +++ b/lib/dir-reader.js @@ -0,0 +1,10 @@ +// 'use strict'; +// +// const fs = require('fs'); +// +// const dataFiles = module.exports = function() { +// fs.readdir(`${__dirname}/../data`, function(err, data) { +// if (err) throw err; +// return data; +// }); +// }; diff --git a/lib/file-reader.js b/lib/file-reader.js new file mode 100644 index 0000000..77a5de9 --- /dev/null +++ b/lib/file-reader.js @@ -0,0 +1,19 @@ +'use strict'; + +const fs = require('fs'); + +module.exports = function(file, callback) { + if (file instanceof Array) { + let results = []; + file.forEach(function(ele, index, array) { + fs.readFile(`${__dirname}/../data/${ele}`, function(err, data) { + if (err) callback(err); + let string = data.toString('hex', 0, 8); + results.push(string); + if (index == (array.length - 1)) callback(null, results); + }); + }); + } else { + callback(new Error('file array not found')); + } +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..1544890 --- /dev/null +++ b/package.json @@ -0,0 +1,27 @@ +{ + "name": "lab03", + "version": "1.0.0", + "description": "![CF](https://camo.githubusercontent.com/70edab54bba80edb7493cad3135e9606781cbb6b/687474703a2f2f692e696d6775722e636f6d2f377635415363382e706e67) Lab 03: Parallel File Processing ===", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/dkulp23/03-parallel_file_processing.git" + }, + "keywords": [], + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/dkulp23/03-parallel_file_processing/issues" + }, + "homepage": "https://github.com/dkulp23/03-parallel_file_processing#readme", + "devDependencies": { + "chai": "^3.5.0", + "gulp": "^3.9.1", + "gulp-eslint": "^3.0.1", + "gulp-mocha": "^4.0.1", + "mocha": "^3.2.0" + } +} diff --git a/test/file-reader-test.js b/test/file-reader-test.js new file mode 100644 index 0000000..96bccb2 --- /dev/null +++ b/test/file-reader-test.js @@ -0,0 +1,32 @@ +'use strict'; + +const expect = require('chai').expect; +const readFile = require('../lib/file-reader.js'); + +describe('File Reader Module', function() { + describe('test false file path', function() { + it('should return an error message', function(done) { + readFile(['imaginary-file.txt'], function(err) { + expect(err).to.be.an('error'); + done(); + }); + }); + }); + + describe('test actual file paths', function() { + let files = ['one.txt', 'two.txt', 'three.txt']; + let expected = ['456e616d656c2070', '536c6f772d636172', '53756363756c656e']; + it('should return the first 8 hex digits in order', function(done) { + readFile(files, function(err, data) { + expect(err).to.equal(null); + expect(data[0]).to.be.a('string'); + expect(data[0]).to.equal(expected[0]); + expect(data[1]).to.be.a('string'); + expect(data[1]).to.equal(expected[1]); + expect(data[2]).to.be.a('string'); + expect(data[2]).to.equal(expected[2]); + done(); + }); + }); + }); +});