diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/file-async.js b/file-async.js new file mode 100644 index 0000000..52c421d --- /dev/null +++ b/file-async.js @@ -0,0 +1,26 @@ +const fs = require('fs'); +const EventEmitter = require('events').EventEmitter; +const ee = new EventEmitter(); + + + +fs.readFile('./one.txt', (err, data) => { + console.log(data.toString('hex',0,8)); + ee.emit('file-two', data); +}) + +ee.on('file-two', () => { + fs.readFile('./two.txt', (err, data) => { + console.log(data.toString('hex',0,8)); + ee.emit('file-three', data); + }) +}) + + +ee.on('file-three', () => { + fs.readFile('./three.txt', (err, data) => { + + console.log(data.toString('hex',0,8)); + }) + +}) diff --git a/one.txt b/one.txt new file mode 100644 index 0000000..1b84884 --- /dev/null +++ b/one.txt @@ -0,0 +1 @@ +First file is the first file diff --git a/package.json b/package.json new file mode 100644 index 0000000..5d5b3fd --- /dev/null +++ b/package.json @@ -0,0 +1,30 @@ +{ + "name": "dstineback", + "version": "1.0.0", + "description": "class-03 lab", + "main": "file-async.js", + "directories": { + "test": "test" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/dstineback/fs_and_async.git" + }, + "author": "me", + "license": "ISC", + "bugs": { + "url": "https://github.com/dstineback/fs_and_async/issues" + }, + "homepage": "https://github.com/dstineback/fs_and_async#readme", + "devDependencies": { + "async": "^2.0.0-rc.4", + "chai": "^3.5.0", + "gulp": "^3.9.1", + "gulp-eslint": "^2.0.0", + "gulp-mocha": "^2.2.0", + "mocha": "^2.4.5" + } +} diff --git a/test/test.js b/test/test.js new file mode 100644 index 0000000..f10c82a --- /dev/null +++ b/test/test.js @@ -0,0 +1,9 @@ +const expect = require('chai').expect +const text = require('../file-async') + +describe('text test', () => { + it('test should log first 8 bites', (done) => { + expect(text()).to.eql('hex'); + done(); + }) +}) diff --git a/three.txt b/three.txt new file mode 100644 index 0000000..2f603eb --- /dev/null +++ b/three.txt @@ -0,0 +1 @@ +three file. Word up. diff --git a/two.txt b/two.txt new file mode 100644 index 0000000..760cfd2 --- /dev/null +++ b/two.txt @@ -0,0 +1 @@ +Two file. Word down.