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
1 change: 1 addition & 0 deletions zach/data/one.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ONE IS MY NUMBER
1 change: 1 addition & 0 deletions zach/data/three.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
THREE IS MY NUMBER
1 change: 1 addition & 0 deletions zach/data/two.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TWO IS MY NUMBER
31 changes: 31 additions & 0 deletions zach/file_read.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const fs = require('fs');
const EventEmitter = require('events').EventEmitter;
const ee = new EventEmitter();
module.exports = exports = {};
module.exports.results = [];

var reader = module.exports.reader = function (file, callback) {
fs.readFile('./data/' + file + '.txt', (err, data) => {
if (err) return console.log(err);
var fileText = data.toString('hex', 0, 8);
console.log(fileText);
module.exports.results.push(fileText);
debugger;
ee.emit('file ' + file + ' read');
if (callback == true && file == 'three') {
callback();
}
})
}

ee.on('file one read', () => {
reader('two');
})

ee.on('file two read', () => {
reader('three');
})

reader('one');

debugger;
21 changes: 21 additions & 0 deletions zach/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "zach",
"version": "1.0.0",
"description": "should console.log the first 8 bytes of three files in order",
"main": "file_read.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "zach simonson",
"license": "ISC",
"devDependencies": {
"chai": "^3.5.0",
"gulp": "^3.9.1",
"gulp-eslint": "^2.0.0",
"gulp-mocha": "^2.2.0",
"mocha": "^2.4.5"
}
}
28 changes: 28 additions & 0 deletions zach/test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var mocha = require('mocha');
var expect = require('chai').expect;
var readerFile = require('../file_read.js');

describe('Reader', function() {
before(function(done) {
readerFile.reader('one', done);
});
it('it should read the first file and return the correct string of eight hexes', function() {
var results = readerFile.results[0];
var expected = '4f4e45204953204d';

expect(results).to.deep.equal(expected);
});
it('it should read the second file and return the correct string of eight hexes', function() {
var results = readerFile.results[1];
var expected = '54574f204953204d';

expect(results).to.deep.equal(expected);

});
it('it should read the third file and return the correct string of eight hexes', function() {
var results = readerFile.results[2];
var expected = '5448524545204953';

expect(results).to.deep.equal(expected);
})
})