-
Notifications
You must be signed in to change notification settings - Fork 15
log files hex data in order #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| babnsnsnmnmnmnmnmnmnmn file one |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hellllllloooooo file three |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| askjdhsakjhdkajshdkjashdkajshdk file two | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| 'use strict'; | ||
| var box = []; | ||
|
|
||
| exports.box = box; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| }); | ||
| }); | ||
| }); | ||
| 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(); | ||
| }; |
| 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); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great work returning the callback with null passed in for the error. |
||
| }); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "name": "03-parallel_file_processing", | ||
| "version": "1.0.0", | ||
| "description": " 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" | ||
| } | ||
| } |
| 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'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is your eslintrc file? |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice keyboard faceroll. :)