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
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/node_modules/*
**/vendor/*
**/*.min.js
**/coverage/*
**/build/*
41 changes: 41 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"env": {
"browser": true,
"node": true,
"commonjs": true,
"jest": true,
"es6": true
},
"globals": {
"err": true,
"req": true,
"res": true,
"next": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"no-console": "off",
"indent": [
"error",
2
],
"quotes": [
"error",
"single",
{
"allowTemplateLiterals": true
}
],
"comma-dangle": [
"error",
"always-multiline"
],
"semi": [
"error",
"always"
]
}
}
93 changes: 93 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@

# Created by https://www.gitignore.io/api/osx,node

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
node_modules

# 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


### 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

# End of https://www.gitignore.io/api/osx,node
48 changes: 8 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,14 @@
![CF](https://camo.githubusercontent.com/70edab54bba80edb7493cad3135e9606781cbb6b/687474703a2f2f692e696d6775722e636f6d2f377635415363382e706e67) 03: Parallel File Processing
===
## Documentation
This app takes in three files and sends the contents of each as a string to a new index in an array.

## Submission Instructions
* Work in a fork of this repository
* Work in a branch on your fork
* Write all of your code in a directory named `lab-` + `<your name>` **e.g.** `lab-susan`
* Open a pull request to this repository
* Submit on canvas a question and observation, how long you spent, and a link to your pull request
## File Reader Function

## Resources
* [fs module docs](https://nodejs.org/api/fs.html)
My file reader function takes in two parameters, the paths (array) and a callback (function). The array must contain strings which are derived from the assets directory, each file contained within is mapped to a variable declared within the reader module.

## Configuration
Configure the root of your repository with the following files and directories. Thoughtfully name and organize any aditional configuration or module files.
* **README.md** - contains documentation
* **.gitignore** - contains a [robust](http://gitignore.io) `.gitignore` file
* **.eslintrc.json** - contains the course linter configuration
* **.eslintignore** - contains the course linter ignore configuration
* **package.json** - contains npm package config
* create a `lint` script for running eslint
* create a `test` script for running tests
* **lib/** - contains module definitions
* **assets/** - contains the text files used by the program
* **\_\_test\_\_/** - contains unit tests
## File Reader Array Test

## Feature Tasks
#### Reader Module
In the lib/ directory create a reader.js module that exports a single function. The reader module should take an array of three file paths and resolve a mapped array of strings loaded from each file using an error-first callback. The string data should be in the same order as the file path data (mapped). If an error occurs it should immediately reject the error using the callback and stop execution.
My file reader test passes in three correct files in the form of an array and shows an error if it were to be null, and the test passes if three text files are passed as expected.

* The reader module should have the function signature `(paths, callback) => undefined`
* On a failure the reader module should invoke the callback with an error `callback(error)`
* On success the reader module should invoke the callback with null as the first parameter, and the result as the second parameter `callback(null, result)`
## File Reader Invalid Array Test

## Testing
#### Reader Module Tests
* Use TDD `describe` and `test` methods to define descriptive tests
* Each `test` callback should aim to test a small well defined feature of a function
* Write tests to ensure the reader function rejects errors with invalid file paths
* Write tests to ensure the reader function correctly resolves mapped string data for an array of file paths

## Bonus 1pt
Write the reader function recursively so that it will be able to support 0 or more paths.

## Documentation
In your README.md describe the exported values of each module you have defined. Every function description should include it's arity (expected number of parameters), the expected data for each parameter (data-type and limitations), and it's behavior (for both valid and invalid use). Feel free to write any additional information in your README.md.
My file reader invalid tests look at each index of the array passed to it and determines whether at index 0, 1, or 2 if an invalid text file is passed through. If it is invalid, it throws an error.
34 changes: 34 additions & 0 deletions __test__/file-reader.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

const fileReader = require('../lib/file-reader');

describe('file-reader.test.js', () => {
test('All text found', (done) => {
fileReader.readFile(['kafka.txt', 'panagram.txt', 'werther.txt'], (error, data) => {
expect(error).toBeNull();
expect(data).toEqual(['One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin.', 'The quick, brown fox jumps over a lazy dog. DJs flock by when MTV ax quiz prog.', ' wonderful serenity has taken possession of my entire soul, like these sweet mornings of spring which I enjoy with my whole heart.']);
done();
});
});

test('Each file received must be valid file', done => {
fileReader.readFile(['garbage', 'panagram.txt', 'werther.txt'], (error) => {
expect(error).not.toBeNull();
done();
});
});

test('Each file received must be valid file', done => {
fileReader.readFile(['kafka.txt', 'garbage', 'werther.txt'], (error) => {
expect(error).not.toBeNull();
done();
});
});

test('Each file received must be valid file', done => {
fileReader.readFile(['kafka.txt', 'panagram.txt', 'garbage'], (error) => {
expect(error).not.toBeNull();
done();
});
});
});
1 change: 1 addition & 0 deletions assets/kafka.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin.
1 change: 1 addition & 0 deletions assets/panagram.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The quick, brown fox jumps over a lazy dog. DJs flock by when MTV ax quiz prog.
1 change: 1 addition & 0 deletions assets/werther.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wonderful serenity has taken possession of my entire soul, like these sweet mornings of spring which I enjoy with my whole heart.
34 changes: 34 additions & 0 deletions lib/file-reader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

const reader = module.exports = {};
const fs = require('fs');

reader.readFile = (paths, callback) => {
let ipsumArr = [];
let kafkaFile = `${__dirname}/../assets/${paths[0]}`;
let panagramFile = `${__dirname}/../assets/${paths[1]}`;
let wertherFile = `${__dirname}/../assets/${paths[2]}`;

fs.readFile(kafkaFile, (error, data) => {

if(error)
return callback(error);

ipsumArr.push(data.toString());

fs.readFile(panagramFile, (error, data) => {
if (error)
return callback(error);
ipsumArr.push(data.toString());

fs.readFile(wertherFile, (error, data) => {
if (error)
return callback(error);

ipsumArr.push(data.toString());

callback(null, ipsumArr);
});
});
});
};
Loading