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 lab-catherine/.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 lab-catherine/.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" ]
}
}
92 changes: 92 additions & 0 deletions lab-catherine/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@

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

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

# End of https://www.gitignore.io/api/osx,node
3 changes: 3 additions & 0 deletions lab-catherine/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Lab 03: Parallel File Processing

In reader.js the exported module is an object with the textReader.readText function attached. The function has an arity of two (paths and callback). Paths is an array of filepaths to .txt files. Callback is the callback function which is sending the content of the array of .txt files. To return an array of strings containing the contents of the three text files, the three filepaths passed in the array must be valid. If those three filepaths are invalid, then an error object will be returned.
29 changes: 29 additions & 0 deletions lab-catherine/__test__/reader.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const textReader = require('../lib/reader');
const paths = [`${__dirname}/../assets/cat.txt`, `${__dirname}/../assets/elephant.txt`,`${__dirname}/../assets/seal.txt`];
const invalidPaths = [`${__dirname}/../assets/cat`, `${__dirname}/../assets/elephant`,`${__dirname}/../assets/seal`];

describe('reader.test.js', () => {

describe('testing to see if file text and file paths are displaying correctly', () => {

test('return the file text if there are no errors',
(done) => {
textReader.readText(paths, (error, data) => {
expect(error).toBeNull();
expect(data).toEqual([`Cats say meow!`, `Elephants are the largest land animals in the world.`, `Seals spend much of their life in water, but they mate, give birth to babies and take care of them on the shore.`]);
done();
});
});
});

describe('testing to see that incorrect file paths throw an error', () => {

test('throw an error if invalid file path', () => {
textReader.readText(invalidPaths, (error) => {
expect(error).not.toBeNull();
});
});
});
});
1 change: 1 addition & 0 deletions lab-catherine/assets/cat.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cats say meow!
1 change: 1 addition & 0 deletions lab-catherine/assets/elephant.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Elephants are the largest land animals in the world.
1 change: 1 addition & 0 deletions lab-catherine/assets/seal.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Seals spend much of their life in water, but they mate, give birth to babies and take care of them on the shore.
21 changes: 21 additions & 0 deletions lab-catherine/lib/reader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

const textReader = module.exports = {};
const fs = require('fs');
const fileTextArray = [];

textReader.readText = (paths, callback) => {
fs.readFile(paths[0], (error, data) => {
if(error) return callback(error);
fileTextArray.push(data.toString());
fs.readFile(paths[1], (error, data) => {
if(error) return callback(error);
fileTextArray.push(data.toString());
fs.readFile(paths[2], (error, data) => {
if(error) return callback(error);
fileTextArray.push(data.toString());
callback(null, fileTextArray);
});
});
});
};
Loading