Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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.
3 changes: 3 additions & 0 deletions data/three.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
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.

Keffiyeh fap letterpress succulents, man braid slow-carb activated charcoal. Etsy hammock food truck, jean shorts blue bottle migas small batch bitters bicycle rights yuccie poutine. Cronut 3 wolf moon poke, squid tumblr disrupt offal retro bushwick fingerstache fanny pack williamsburg. Cray actually gluten-free, fashion axe sustainable raw denim keytar flexitarian kogi 90's. Whatever lomo trust fund fam ethical, freegan yuccie next level franzen viral. Man bun literally cornhole, kogi master cleanse brunch marfa seitan farm-to-table XOXO. Church-key meh poutine etsy fap normcore plaid, pickled ugh pabst pinterest.
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.
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// 'use strict';
//
// const reader = require('./lib/file-reader.js').readFiles;
//
// reader(['one.txt', 'two.txt', 'three.txt']);

Choose a reason for hiding this comment

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

You'll want to be able to call your method here in your index with all 3 of your files, and your callback function as your final argument to the function.

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;
// });
// };
37 changes: 37 additions & 0 deletions lib/file-reader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict';

const fs = require('fs');

module.exports = exports = {};

exports.readFiles = function(file, callback) {
if (file instanceof Array) {//linter wouldn't let me use (! instanceof)
file.map(function(ele) {
fs.readFile(`${__dirname}/../data/${ele}`, function(err, data) {
if (err) return callback(err);

Choose a reason for hiding this comment

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

Cool, this is the correct pattern for handling an error if it comes up and returning it.

let string = data.toString('hex').substring(0, 8);
console.log(string);
return callback(null, string);
});
});
} else {
throw new Error('file name array not found');
}
};

// exports.readFiles = function(file, callback) {
// if (file instanceof Array) {//linter wouldn't let me use (! instanceof)
// let fileResults = file.reduce(function(acc, ele) {
// fs.readFile(`${__dirname}/../data/${ele}`, function(err, data) {
// if (err) throw err;
// let string = data.toString('hex').substring(0, 8);
// acc.push(string);
// return acc;
// });
// }, []);
// // callback(null, fileResults);
// console.log(fileResults);
// } else {
// throw new Error('file name array not found');
// }
// };
25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"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",
"mocha": "^3.2.0"
}
}
25 changes: 25 additions & 0 deletions test/file-reader-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

const expect = require('chai').expect;
const readFile = require('../lib/file-reader.js').readFiles;

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() {
it('should return the first 8 hex digits', function(done) {
readFile(['one.txt', 'two.txt', 'three.txt'], function(err, data) {
expect(err).to.equal(null);
expect(data).to.be.a('string');

Choose a reason for hiding this comment

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

This is good, but for this test you'll want to ensure that the three files come back in the proper order. Good way to do that would be to check the values of the returning data's indices at [0], then [1], then [2].

Test is structured mostly right, though.

done();
});
});
});
});