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
6 changes: 2 additions & 4 deletions README.md → DIRECTIONS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
![CF](https://camo.githubusercontent.com/70edab54bba80edb7493cad3135e9606781cbb6b/687474703a2f2f692e696d6775722e636f6d2f377635415363382e706e67) 03: Parallel File Processing
===

## Submission Instructions
* Work in a fork of this repository
Expand All @@ -11,10 +9,10 @@
## Resources
* [fs module docs](https://nodejs.org/api/fs.html)

## Configuration
## 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
* **.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
Expand Down
5 changes: 5 additions & 0 deletions lab-nicholasc/.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-nicholasc/.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" ]
}
}
80 changes: 80 additions & 0 deletions lab-nicholasc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@

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

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


# End of https://www.gitignore.io/api/node,linux
12 changes: 12 additions & 0 deletions lab-nicholasc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Lab 03

## exports

###reader
reader exports four customized functions that affect arrays
####reader.readFile
takes in an array of paths and a callback function, and returns an array stringified files. it also catches errors and returns a descriptive error message
####reader.readFiles
takes in an array of paths and a callback function, and returns an array stringified files. it also catches errors and returns a descriptive error message. The files will stay arranged as they come in because of the recursive nature of the function.
#### NOTES
I am now in the process of refactoring to recursive functions and fixing my original functionality. The readFiles function is structured like the one during code review, I intend to improve on my testing.
42 changes: 42 additions & 0 deletions lab-nicholasc/__test__/reader.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict';

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

describe('reader.test.js', () => {
test('should be 64 char', done => {
reader.readFiles(
[
`${__dirname}/../assets/mario.txt`,
`${__dirname}/../assets/peach.txt`,
`${__dirname}/../assets/luigi.txt`,
],
(error, data) => {
expect(error).toBeNull();
expect(data[0].length).toEqual(5);
done();
});
});

test('should throw error if bad file', done => {
reader.readFiles(
[`${__dirname}/../assets/luig.bad`, `${__dirname}/../assets/mario.txt`, `${__dirname}/../assets/peach.txt`],
(error, data) => {
expect(error).toBeTruthy();
done();
});
});

test('file contents should be returned in order based on input array', done => {
let filePaths = [
`${__dirname}/../assets/mario.txt`,
`${__dirname}/../assets/peach.txt`,
`${__dirname}/../assets/luigi.txt`,
];
reader.readFiles(filePaths, (error,data) => {
expect(data[0]).toEqual('mario');
expect(data[1]).toEqual('peach');
expect(data[2]).toEqual('luigi');
done();
});
});
});
1 change: 1 addition & 0 deletions lab-nicholasc/assets/luigi.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
luigi
1 change: 1 addition & 0 deletions lab-nicholasc/assets/mario.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mario
1 change: 1 addition & 0 deletions lab-nicholasc/assets/peach.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
peach
1 change: 1 addition & 0 deletions lab-nicholasc/less-than-64.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#asdf
25 changes: 25 additions & 0 deletions lab-nicholasc/lib/reader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';


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

reader.readFiles = (paths, callback) => {
let results = [];
function readFilesRecursively(){
if(paths.length === 0)
callback(null, results);
else
fs.readFile(paths.shift(), (error,data) => {
if(error){
callback(error, null);
return;
}

results.push(data.toString('utf-8', 0, 5));
readFilesRecursively();
});
}

readFilesRecursively();
};
Loading