From f3c429df3349177af2eb87b2b7f42cf2a0c68d42 Mon Sep 17 00:00:00 2001 From: Stephen Schroeder Date: Thu, 12 May 2016 12:57:59 -0700 Subject: [PATCH 1/3] i got something but not much --- Stephen_Schroeder/.gitignore | 2 ++ Stephen_Schroeder/main.js | 35 ++++++++++++++++++++++++++ Stephen_Schroeder/package.json | 18 +++++++++++++ Stephen_Schroeder/test/test.js | 10 ++++++++ Stephen_Schroeder/text_files/one.txt | 1 + Stephen_Schroeder/text_files/three.txt | 1 + Stephen_Schroeder/text_files/two.txt | 1 + 7 files changed, 68 insertions(+) create mode 100644 Stephen_Schroeder/.gitignore create mode 100644 Stephen_Schroeder/main.js create mode 100644 Stephen_Schroeder/package.json create mode 100644 Stephen_Schroeder/test/test.js create mode 100644 Stephen_Schroeder/text_files/one.txt create mode 100644 Stephen_Schroeder/text_files/three.txt create mode 100644 Stephen_Schroeder/text_files/two.txt diff --git a/Stephen_Schroeder/.gitignore b/Stephen_Schroeder/.gitignore new file mode 100644 index 0000000..fd4f2b0 --- /dev/null +++ b/Stephen_Schroeder/.gitignore @@ -0,0 +1,2 @@ +node_modules +.DS_Store diff --git a/Stephen_Schroeder/main.js b/Stephen_Schroeder/main.js new file mode 100644 index 0000000..3f883bb --- /dev/null +++ b/Stephen_Schroeder/main.js @@ -0,0 +1,35 @@ +const main = exports = module.exports; +const fs = require('fs'); +const EventEmitter = require('events').EventEmitter; +const ee = new EventEmitter(); + +var fileList = ['text_files/one.txt', 'text_files/two.txt', 'text_files/three.txt']; + +var finalArray = []; + +fs.readFile('text_files/one.txt', (err, data) => { + console.log(data.toString('hex', 0, 8)); + finalArray.push(0); + ee.emit('one'); +}) + +ee.on('one', () => { + fs.readFile('text_files/two.txt', (err, data) => { + console.log(data.toString('hex', 0, 8)); + finalArray.push(1); + ee.emit('two'); + }) +}) + +ee.on('two', () => { + fs.readFile('text_files/three.txt', (err, data) => { + console.log(data.toString('hes', 0, 8)); + finalArray.push(2); + }) +}) + +main.runIt = () => { + return finalArray; +} + +debugger; diff --git a/Stephen_Schroeder/package.json b/Stephen_Schroeder/package.json new file mode 100644 index 0000000..7001110 --- /dev/null +++ b/Stephen_Schroeder/package.json @@ -0,0 +1,18 @@ +{ + "name": "fs_and_async", + "version": "0.1.0", + "description": "testing using buffers and event emitters", + "main": "main.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Stephen Schroeder", + "license": "ISC", + "devDependencies": { + "async": "^1.5.2", + "chai": "^3.5.0", + "gulp": "^3.9.1", + "gulp-install": "^0.6.0", + "mocha": "^2.4.5" + } +} diff --git a/Stephen_Schroeder/test/test.js b/Stephen_Schroeder/test/test.js new file mode 100644 index 0000000..a5047ec --- /dev/null +++ b/Stephen_Schroeder/test/test.js @@ -0,0 +1,10 @@ +const chai = require('chai'); +const main = require('../main'); + +describe('readFile processes', () => { + it('should have an 8 byte value of hex', () => { + fs.readFile(__dirname + '/../one.txt', () => { + expect() + }) + }) +}) diff --git a/Stephen_Schroeder/text_files/one.txt b/Stephen_Schroeder/text_files/one.txt new file mode 100644 index 0000000..1071e29 --- /dev/null +++ b/Stephen_Schroeder/text_files/one.txt @@ -0,0 +1 @@ +Larry like cake and pies. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.lorem diff --git a/Stephen_Schroeder/text_files/three.txt b/Stephen_Schroeder/text_files/three.txt new file mode 100644 index 0000000..d866106 --- /dev/null +++ b/Stephen_Schroeder/text_files/three.txt @@ -0,0 +1 @@ +Sally likes weed and beer. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. diff --git a/Stephen_Schroeder/text_files/two.txt b/Stephen_Schroeder/text_files/two.txt new file mode 100644 index 0000000..112a30f --- /dev/null +++ b/Stephen_Schroeder/text_files/two.txt @@ -0,0 +1 @@ +George likes to kill people. Nobody likes George. Don't be like George.Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. From 6934e997c27d4cc4397c3f998f8df189a82cfc3c Mon Sep 17 00:00:00 2001 From: Stephen Schroeder Date: Fri, 13 May 2016 09:44:14 -0700 Subject: [PATCH 2/3] some tweeks --- Stephen_Schroeder/main.js | 49 +++++++++++++++++----------------- Stephen_Schroeder/test/test.js | 44 ++++++++++++++++++++++++------ 2 files changed, 61 insertions(+), 32 deletions(-) diff --git a/Stephen_Schroeder/main.js b/Stephen_Schroeder/main.js index 3f883bb..bff2d03 100644 --- a/Stephen_Schroeder/main.js +++ b/Stephen_Schroeder/main.js @@ -1,35 +1,36 @@ -const main = exports = module.exports; +'use strict'; const fs = require('fs'); -const EventEmitter = require('events').EventEmitter; -const ee = new EventEmitter(); +const ee = new(require('events').EventEmitter); var fileList = ['text_files/one.txt', 'text_files/two.txt', 'text_files/three.txt']; -var finalArray = []; - -fs.readFile('text_files/one.txt', (err, data) => { - console.log(data.toString('hex', 0, 8)); - finalArray.push(0); - ee.emit('one'); -}) - -ee.on('one', () => { - fs.readFile('text_files/two.txt', (err, data) => { +var mainReader = module.exports = function(cb) { + let finalArray = []; + fs.readFile('text_files/one.txt', (err, data) => { console.log(data.toString('hex', 0, 8)); - finalArray.push(1); - ee.emit('two'); - }) -}) + finalArray.push(0); + ee.emit('one'); + }); -ee.on('two', () => { - fs.readFile('text_files/three.txt', (err, data) => { - console.log(data.toString('hes', 0, 8)); - finalArray.push(2); + ee.on('one', () => { + fs.readFile('text_files/two.txt', (err, data) => { + console.log(data.toString('hex', 0, 8)); + finalArray.push(1); + ee.emit('two'); + }); + }); + + ee.on('two', () => { + fs.readFile('text_files/three.txt', (err, data) => { + console.log(data.toString('hex', 0, 8)); + finalArray.push(2); + cb.files + }) }) -}) +} -main.runIt = () => { +mainReader((finalArray) => { return finalArray; -} +}) debugger; diff --git a/Stephen_Schroeder/test/test.js b/Stephen_Schroeder/test/test.js index a5047ec..7fca48e 100644 --- a/Stephen_Schroeder/test/test.js +++ b/Stephen_Schroeder/test/test.js @@ -1,10 +1,38 @@ -const chai = require('chai'); -const main = require('../main'); +'use strict'; + +const expect = require('chai').expect; +const mainReader = require('../main.js'); +const fs = require('fs'); describe('readFile processes', () => { - it('should have an 8 byte value of hex', () => { - fs.readFile(__dirname + '/../one.txt', () => { - expect() - }) - }) -}) + let files; + before((done) => { + files = []; + fs.readFile(__dirname + '/../text_files/one.txt', (err, data) => { + console.log('one'); + files.push(data.slice(0, 8)); + fs.readFile(__dirname + '/../text_files/two.txt', (err, data) => { + console.log('two'); + files.push(data.slice(0, 8)); + fs.readFile(__dirname + '/../text_files/three.txt', (err, data) => { + console.log('three'); + files.push(data.slice(0, 8)); + done(); + }); + }); + }); + }); + + it('should read files correctly', () => { + mainReader((files) => { + expect(Buffer.isBuffer(files[0])).to.equal(true); + done(); + }); + }); + + it('should keep files in correct order', (done) => { + mainReader((data) => { + expect(data[0].toString()).to.eql(files[0].toString()); + }); + }); +}); From fdd77d744060593dc778d84e4990e648815f6e4c Mon Sep 17 00:00:00 2001 From: Stephen Schroeder Date: Thu, 19 May 2016 19:25:02 -0700 Subject: [PATCH 3/3] fixing test --- Stephen_Schroeder/main.js | 1 - Stephen_Schroeder/test/test.js | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Stephen_Schroeder/main.js b/Stephen_Schroeder/main.js index bff2d03..c4a94ce 100644 --- a/Stephen_Schroeder/main.js +++ b/Stephen_Schroeder/main.js @@ -32,5 +32,4 @@ var mainReader = module.exports = function(cb) { mainReader((finalArray) => { return finalArray; }) - debugger; diff --git a/Stephen_Schroeder/test/test.js b/Stephen_Schroeder/test/test.js index 7fca48e..6321198 100644 --- a/Stephen_Schroeder/test/test.js +++ b/Stephen_Schroeder/test/test.js @@ -30,9 +30,9 @@ describe('readFile processes', () => { }); }); - it('should keep files in correct order', (done) => { + it('should keep files in correct order', () => { mainReader((data) => { - expect(data[0].toString()).to.eql(files[0].toString()); + expect(mainReader.finalArray).to.eql('abc'); }); }); });