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/*
26 changes: 26 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"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" ]
}
}
145 changes: 145 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# 401 JS
db
.env
temp
build

# Created by https://www.gitignore.io/api/vim,osx,node,linux,windows
### 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*

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


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

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

### 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/vim,osx,node,linux,windows
47 changes: 6 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,11 @@
![CF](https://camo.githubusercontent.com/70edab54bba80edb7493cad3135e9606781cbb6b/687474703a2f2f692e696d6775722e636f6d2f377635415363382e706e67) 03: Parallel File Processing
===

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

## Resources
* [fs module docs](https://nodejs.org/api/fs.html)

## Configuration
Configure the root of your repository with the following files and directories. Thoughfully name and organize any aditional configuration or module files.
* **README.md** - contains documentation
* **.gitignore** - contains a [robust](http://gitignore.io) `.gitignore` file
* **.eslintrc** - contains the course linter configuratoin
* **.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

## Feature Tasks
## Exported Values
#### 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 immediatly reject the error using the callback and stop execution.

* 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 paramiter, and the result as the second paramiter `callback(null, result)`

## Testing
#### Reader Module Tests
* Use BDD `describe` and `test` methods to define discriptive tests and increase readablity
* 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 recursivly so that it will be able to support 0 or more paths.
The reader module exports a single function. It takes an array of three file paths and resolves 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.

## Documentation
In your README.md describe the exported values of each module you have defined. Every function description should include it's airty (expected number of paramiters), the expected data for each paramiter (data-type and limitations), and it's behavior (for both valid and invalued use). Feel free to write any additional information in your README.md.
* The reader module's read function has an arity of one.
* The expected data for each parameter is an array holding strings representing file paths.`
* On a failure, it should invoke the callback with an error `callback(error)`
* On success, it should invoke the callback with null as the first paramiter, and the result as the second paramiter `callback(null, result)`
1 change: 1 addition & 0 deletions __test__/assets/cats.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ANIMALER
1 change: 1 addition & 0 deletions __test__/assets/dogs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ANIMALEST
1 change: 1 addition & 0 deletions __test__/assets/horses.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ANIMAL
22 changes: 22 additions & 0 deletions __test__/reader.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

const reader = require('../lib/reader.js');

describe('reader', () => {
test('an invalid path should reject an error', (done) => {
reader.read([`${__dirname}/assets/pets.txt`,`${__dirname}/assets/pets.txt`,`${__dirname}/assets/pets.txt`], (err, data) => {
expect(err).not.toBe(null);
expect(data).toBeUndefined();
done();
});
});

test('a valid path should resolve a lowercased string', (done) => {
reader.read([`${__dirname}/assets/horses.txt`,`${__dirname}/assets/cats.txt`,`${__dirname}/assets/dogs.txt`], (err, data) => {

expect(err).toBeNull();
expect(data).toEqual([ 'animal\n', 'animaler\n', 'animalest\n' ]);
done();
});
});
});
21 changes: 21 additions & 0 deletions lib/reader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

const fs = require('fs');

const read = (paths, callback) => {
var strings = [];
for (var i = 0; i < paths.length; i++) {
fs.readFile(paths[i], (err, data) => {
if(err)
return callback(err);
strings.push(data.toString().toLowerCase());
if (strings.length === 3) {
callback(null, strings.sort());
}
});
}
};

module.exports = {
read: read,
};
25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "03-asynchronous-callbacks",
"version": "0.0.0",
"description": "![CF](https://camo.githubusercontent.com/70edab54bba80edb7493cad3135e9606781cbb6b/687474703a2f2f692e696d6775722e636f6d2f377635415363382e706e67) 03: Parallel File Processing ===",
"main": "index.js",
"scripts": {
"lint": "eslint .",
"test": "jest --coverage -i",
"test-watch": "jest --watch -i"
},
"repository": {
"type": "git",
"url": "git+https://github.com/KatherineHanson/03-asynchronous-callbacks.git"
},
"keywords": [],
"author": "katherinemariehanson@gmail.com",
"license": "ISC",
"bugs": {
"url": "https://github.com/KatherineHanson/03-asynchronous-callbacks/issues"
},
"homepage": "https://github.com/KatherineHanson/03-asynchronous-callbacks#readme",
"devDependencies": {
"jest": "^21.0.2"
}
}