Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -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"
}
114 changes: 114 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions data/one.txt
Original file line number Diff line number Diff line change
@@ -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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay lorem ipsum stuff. :)


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.
2 changes: 2 additions & 0 deletions data/three.txt
Original file line number Diff line number Diff line change
@@ -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.

3 changes: 3 additions & 0 deletions data/two.txt
Original file line number Diff line number Diff line change
@@ -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.
23 changes: 23 additions & 0 deletions gulpfile.js
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('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']);
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -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);
});
10 changes: 10 additions & 0 deletions lib/dir-reader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// 'use strict';
//
// const fs = require('fs');
//
// const dataFiles = module.exports = function() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is heading in the correct direction. You need to figure out how to structure your function dataFils so that it can take the files you want to read, and then take a callback function as a final argument.

// fs.readdir(`${__dirname}/../data`, function(err, data) {
// if (err) throw err;
// return data;
// });
// };
19 changes: 19 additions & 0 deletions lib/file-reader.js
Original file line number Diff line number Diff line change
@@ -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'));
}
};
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
32 changes: 32 additions & 0 deletions test/file-reader-test.js
Original file line number Diff line number Diff line change
@@ -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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good test; this should work fine when your method is working properly.

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();
});
});
});
});