Skip to content
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

Yana - revisions #18

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
117 changes: 117 additions & 0 deletions lab-yana/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Created by https://www.gitignore.io/api/node,vim,osx,macos,linux

*node_modules

### Node ###
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity



### Vim ###
# swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-v][a-z]
[._]sw[a-p]
# session
Session.vim
# temporary
.netrwhist
*~
# auto-generated tag files
tags


### OSX ###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk


### macOS ###
# Icon must end with two \r
# Thumbnails
# Files that might appear in the root of a volume
# Directories potentially created on remote AFP share


### Linux ###

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

# End of https://www.gitignore.io/api/node,vim,osx,macos,linux
624 changes: 624 additions & 0 deletions lab-yana/data/one.txt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lab-yana/data/three.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is the best file content. It is so good.
1 change: 1 addition & 0 deletions lab-yana/data/two.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I'm not sure what to say about the contents of this file, except that it is superior to anything else.
20 changes: 20 additions & 0 deletions lab-yana/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

const gulp = require('gulp');
const eslint = require('gulp-eslint');
const mocha = require('gulp-mocha');

gulp.task('test', function() {
gulp.src('./test/*-test.js', { read: false })
.pipe(mocha({ reporter: 'spec' }));
});

gulp.task('lint', function() {
return gulp.src(['./**/*.js', '!node_modules/**']).pipe(eslint()).pipe(eslint.format()).pipe(eslint.failAfterError());
Copy link

Choose a reason for hiding this comment

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

This might be more readable if you drop each .pipe onto the next line.

});

gulp.task('dev', function() {
gulp.watch(['**/*.js', '!node_modules/**'], ['lint', 'test']);
});

gulp.task('default', ['dev']);
5 changes: 5 additions & 0 deletions lab-yana/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

const reader = require(`${__dirname}/lib/read-files.js`);

reader.fetchFiles(reader.files, reader.readFiles, reader.logThem);
Copy link

Choose a reason for hiding this comment

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

Good Job making this callable from index.js.

34 changes: 34 additions & 0 deletions lab-yana/lib/read-files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

const fs = require('fs');
module.exports = exports = {};
exports.files = [`${__dirname}/../data/one.txt`, `${__dirname}/../data/two.txt`, `${__dirname}/../data/three.txt`];

Copy link

Choose a reason for hiding this comment

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

I like that you put your file paths in an array.

exports.fetchFiles = function(files, iterator, cb) {
var resultsArray = [];
var doneCount = 0;
function isComplete(err, data) {
if (err) throw err;
doneCount += 1;
if(doneCount === files.length) {
cb(data);
}
}
for (let i = 0; i < files.length; i++) {
iterator(files[i], resultsArray, isComplete);
}
}

exports.logThem = function(data) {
console.log(data);
}

exports.readFiles = function(file, resultsArray, cb) {
fs.readFile(file, function(err, data) {
if (err) return cb(err);
let filename = file.slice(file.lastIndexOf('/') + 1 , file.length + 1);
let fileorder = exports.files.indexOf(file);
resultsArray[fileorder] = `first eight bytes of ${filename}: ${data.toString('hex', 0, 8)}`;
cb(null, resultsArray);
});
}
22 changes: 22 additions & 0 deletions lab-yana/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "lab-yana",
"version": "1.0.0",
"description": "",
"main": "gulpfule.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"chai": "^3.5.0",
"gulp": "^3.9.1",
"gulp-eslint": "^3.0.1",
"gulp-mocha": "^3.0.1",
"mocha": "^3.2.0"
}
}
37 changes: 37 additions & 0 deletions lab-yana/test/read-files-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict';

const fs = require('fs');
const expect = require('chai').expect;
const reader = require('../lib/read-files.js');

describe('File Reader Module', function() {
describe('with an improper file path', function() {
it('should return error', function(done) {
let resArray = [];
reader.readFiles(`${__dirname}/../data/not-valid-path.txt`, resArray, function(err) {
expect(err).to.be.an('error');
done();
});
});
});
describe('with a proper file path', function() {
it('should not return an error', function(done) {
let resArray = [];
reader.readFiles(`${__dirname}/../data/one.txt`, resArray, function(err, data) {
expect(err).to.equal(null);
done();
});
});
});
describe('#fetchFiles', function() {
it('should log in order one, two, three', function(done) {
reader.fetchFiles(reader.files, reader.readFiles, function(data) {
expect(data.length).to.equal(3);
expect(data[0]).to.include('one');
expect(data[1]).to.include('two');
expect(data[2]).to.include('three');
done();
});
Copy link

Choose a reason for hiding this comment

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

Good job verifying the order of your file reads.

});
});
});