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
20 changes: 0 additions & 20 deletions README.md

This file was deleted.

1 change: 1 addition & 0 deletions data/one.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
babnsnsnmnmnmnmnmnmnmn file one
1 change: 1 addition & 0 deletions data/three.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hellllllloooooo file three
1 change: 1 addition & 0 deletions data/two.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
askjdhsakjhdkajshdkjashdkajshdk file two

Choose a reason for hiding this comment

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

Nice keyboard faceroll. :)

23 changes: 23 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';
var box = [];

exports.box = box;

Choose a reason for hiding this comment

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

Interesting idea to export the array after you've filled it up from your asynchronous calls.

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

fileReader('./data/one.txt', function(err, data) {
var buff1 = Buffer.from(data).toString('hex').substring(0,8);
console.log(buff1, data);
box.push(buff1);
fileReader('./data/two.txt', function(err, data) {
var buff2 = Buffer.from(data).toString('hex').substring(0,8);
console.log(buff2, data);
box.push(buff2);
fileReader('./data/three.txt', function(err, data) {
var buff3 = Buffer.from(data).toString('hex').substring(0,8);
console.log(buff3, data);
box.push(buff3);
console.log(box );

Choose a reason for hiding this comment

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

When turning in assignments, try to remove console logs like these and the ones above before you turn it in. Get in the habit of not leaving them in when you turn stuff in.

});
});
});
29 changes: 29 additions & 0 deletions lib/error-middleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const createError = require('http-errors');
const debug = require('debug')('cfgram:error-middleware');

module.exports = function(err, req, res, next) {
debug('error middleware');

console.error('msg:', err.message);
console.error('name:', err.name);

if (err.name === 'ValidationError') {
err = createError(400, err.message);
res.status(err.status).send(err.name);
next();
return;
}

if (err.status) {
res.status(err.status).send(err.name);
next();
return;
}


err = createError(500, err.message);
res.status(err.status).send(err.name);
next();
};
9 changes: 9 additions & 0 deletions lib/file-reader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

const fs = require('fs');
const fileReader = module.exports = function(file, callback) {
fs.readFile(file, 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.

Great work calling the callback with an error if one appears.

return callback(null, data.toString());

Choose a reason for hiding this comment

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

Great work returning the callback with null passed in for the error.

});
};
24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "03-parallel_file_processing",
"version": "1.0.0",
"description": "![CF](https://camo.githubusercontent.com/70edab54bba80edb7493cad3135e9606781cbb6b/687474703a2f2f692e696d6775722e636f6d2f377635415363382e706e67) Lab 03: Parallel File Processing\r ===",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/noahgribbin/03-parallel_file_processing.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/noahgribbin/03-parallel_file_processing/issues"
},
"homepage": "https://github.com/noahgribbin/03-parallel_file_processing#readme",
"devDependencies": {
"chai": "^3.5.0",
"mocha": "^3.2.0"
}
}
31 changes: 31 additions & 0 deletions test/file-reader-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

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

Choose a reason for hiding this comment

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

There's your results array. Cool.


describe('File Reader Module', function(){
describe('with an impropper filepath', function(){
it('should return an error', function(done){
fileReader(`${__dirname}/not-a-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. Nice work on this.

expect(err).to.be.an('error');
done();
});
});
it('should log the hex values in order', function(done){
// TODO: test for logs in correct order

Choose a reason for hiding this comment

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

Need a test here to take the information that you stored in box and ensure that it's in the correct order. You'll need to write a test to handle for that.

// expect(box).to.equal([]);
//
done();
});
});
describe('with a propper file path', function(){
it('should return the contents of the file', function(done){
fileReader(`${__dirname}/../data/one.txt`, function(err, data){

Choose a reason for hiding this comment

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

Cool, so now we know that the function call on a single data file works.

expect(err).to.equal(null);
expect(data).to.equal('this is the first file\r\n');
done();
});
});
});
});

Choose a reason for hiding this comment

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

Where is your eslintrc file?