From 96349c2b319a7daea3a25f1c809f09b12e103971 Mon Sep 17 00:00:00 2001 From: Logan Absher Date: Wed, 19 Jul 2017 21:05:15 -0700 Subject: [PATCH] main functionallity works, tests still failing --- .eslintignore | 5 ++ .eslintrc | 21 +++++++ .gitignore | 136 ++++++++++++++++++++++++++++++++++++++++++++ assets/one.txt | 45 +++++++++++++++ assets/three.txt | 68 ++++++++++++++++++++++ assets/two.txt | 57 +++++++++++++++++++ index.js | 14 +++++ lib/reader.js | 16 ++++++ package.json | 27 +++++++++ test/reader-test.js | 23 ++++++++ 10 files changed, 412 insertions(+) create mode 100644 .eslintignore create mode 100644 .eslintrc create mode 100644 .gitignore create mode 100644 assets/one.txt create mode 100644 assets/three.txt create mode 100644 assets/two.txt create mode 100644 index.js create mode 100644 lib/reader.js create mode 100644 package.json create mode 100644 test/reader-test.js diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..05b1cf3 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,5 @@ +**/node_modules/* +**/vendor/* +**/*.min.js +**/coverage/* +**/build/* diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..8dc6807 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,21 @@ +{ + "rules": { + "no-console": "off", + "indent": [ "error", 2 ], + "quotes": [ "error", "single" ], + "semi": ["error", "always"], + "linebreak-style": [ "error", "unix" ] + }, + "env": { + "es6": true, + "node": true, + "mocha": true, + "jasmine": true + }, + "ecmaFeatures": { + "modules": true, + "experimentalObjectRestSpread": true, + "impliedStrict": true + }, + "extends": "eslint:recommended" +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..345130c --- /dev/null +++ b/.gitignore @@ -0,0 +1,136 @@ +# Created by https://www.gitignore.io/api/osx,vim,node,macos,windows + +### macOS ### +*.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 + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.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 + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Typescript v1 declaration files +typings/ + +# 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 + +# dotenv environment variables file +.env + + +### OSX ### + +# Icon must end with two \r + +# Thumbnails + +# Files that might appear in the root of a volume + +# Directories potentially created on remote AFP share + +### 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 + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.gitignore.io/api/osx,vim,node,macos,windows diff --git a/assets/one.txt b/assets/one.txt new file mode 100644 index 0000000..2db3e35 --- /dev/null +++ b/assets/one.txt @@ -0,0 +1,45 @@ +You sit there in your heartache +Waiting on some beautiful boy to +To save your from your old ways +You play forgiveness +Watch it now, here he comes + +He doesn't look a thing like Jesus +But he talks like a gentlemen +Like you imagined when you were young + +Can we climb this mountain +I don't know +Higher now than ever before +I know we can make it if we take it slow +Let's take it easy +Easy now, watch it go + +We're burning down the highway skyline +On the back of a hurricane that started turning +When you were young +When you were young + +And sometimes you close your eyes +And see the place where you Used to live +When you were young + +They say the devil's water - it ain't so sweet +You don't have to drink right now +But you can dip your feet +Every once in a little while + +You sit there in your heartache +Waiting on some beautiful boy to +To save you from your old ways +You play forgiveness +Watch it now, here he comes + +He doesn't look a thing like Jesus +But he talks like a gentlemen +Like you imagined when you were young +When you were young + +I said he doesn't look a thing like Jesus +He doesn't look a thing like Jesus +But more than you'll ever know diff --git a/assets/three.txt b/assets/three.txt new file mode 100644 index 0000000..1ca16f2 --- /dev/null +++ b/assets/three.txt @@ -0,0 +1,68 @@ +Tonight I'm gonna have myself a real good time +I feel alive and the world I'll turn it inside out - yeah +And floating around in ecstasy +So don't stop me now don't stop me +'Cause I'm having a good time having a good time + +I'm a shooting star leaping through the sky +Like a tiger defying the laws of gravity +I'm a racing car passing by like Lady Godiva +I'm gonna go go go +There's no stopping me + +I'm burnin' through the sky yeah +Two hundred degrees +That's why they call me Mister Fahrenheit +I'm trav'ling at the speed of light +I wanna make a supersonic man out of you + +Don't stop me now I'm having such a good time +I'm having a ball +Don't stop me now +If you wanna have a good time just give me a call +Don't stop me now ('Cause I'm having a good time) +Don't stop me now (Yes I'm havin' a good time) +I don't want to stop at all + +Yeah, I'm a rocket ship on my way to Mars +On a collision course +I am a satellite I'm out of control +I am a sex machine ready to reload +Like an atom bomb about to +Oh oh oh oh oh explode + +I'm burnin' through the sky yeah +Two hundred degrees +That's why they call me Mister Fahrenheit +I'm trav'ling at the speed of light +I wanna make a supersonic woman of you + +Don't stop me don't stop me +Don't stop me hey hey hey +Don't stop me don't stop me +Ooh ooh ooh, I like it +Don't stop me don't stop me +Have a good time good time +Don't stop me don't stop me ah +Oh yeah +Alright + +Oh, I'm burnin' through the sky yeah +Two hundred degrees +That's why they call me Mister Fahrenheit +I'm trav'ling at the speed of light +I wanna make a supersonic man out of you + +Don't stop me now I'm having such a good time +I'm having a ball +Don't stop me now +If you wanna have a good time (wooh) +Just give me a call (alright) +Don't stop me now ('cause I'm having a good time - yeah yeah) +Don't stop me now (yes I'm havin' a good time) +I don't want to stop at all +La da da da daah +Da da da haa +Ha da da ha ha haaa +Ha da daa ha da da aaa +Ooh ooh ooh diff --git a/assets/two.txt b/assets/two.txt new file mode 100644 index 0000000..533993c --- /dev/null +++ b/assets/two.txt @@ -0,0 +1,57 @@ +I'm leaving this place behind +And I'm heading out on the road tonight +I'm off for the winter lands +Way up north to have taught you to stand +Before I commence my ride +I'm asking Lily to be my bride +I know there's another man +But he ain't gonna delay my plans + +I know she's gonna be my wife +Gonna fall in love I'm gonna live my life with her +You know I bet he's not so tough +Ain't afraid of him cause I'm a fool for love + +I've come far to find Big Jim +Well here I am and I guess you him +I see how you got your name +You're tall as hell and broad as a train +They say you a hard-broiled man +And the baddest guy in the whole wide land +Well I'm not afraid to fight +Let's step outside and I'll show you why + +I'm humming like a revved up truck +Never mind the odds I'm gonna try my luck with her +Just tell me when you've had enough +I'm dangerous cause I'm a fool for love + +You know you don't hit half bad +For my love I will lay in the grave tonight +Just wait until I catch my breath +Gonna send you off to an early death + +I lie in the drifting snow +Bleeding out as it covers me up +If Spring comes before I'm found +Just throw my bones in a hole in the ground + +I lost friends along my way +I knew I'd need them eventually +No I'm not afraid to die +Just mad I left Big Jim alive + +I know I should've never looked back +But you ain't gonna win a woman's heart like that +I never should've called his bluff +I was born to lose cause I'm a fool for love + +I stare into the endless sky +And I saw a tale of my life go by +I drift into the great unknown +I really don't know where I'm going + +I stare into the endless sky +And I saw a tale of my life go by +I drift into the great unknown +I really don't know where I'm going diff --git a/index.js b/index.js new file mode 100644 index 0000000..905f8c1 --- /dev/null +++ b/index.js @@ -0,0 +1,14 @@ +'use strict'; + +const fr = require('./lib/reader.js'); + +module.exports = exports = {}; + +exports.fileRunner = (err, data) => { + const filesNames = ['one.txt', 'two.txt', 'three.txt']; + filesNames.forEach((ele) => { + fr.fileReader(ele, err); + }); +}; +// NOTE: uncomment to run with node +// exports.fileRunner(); diff --git a/lib/reader.js b/lib/reader.js new file mode 100644 index 0000000..c31dd54 --- /dev/null +++ b/lib/reader.js @@ -0,0 +1,16 @@ +'use strict'; + +const fs = require('fs'); + +module.exports = exports = {}; + +exports.fileReader = (file, callback) => { + fs.readFile(`${__dirname}/../assets/${file}`, (err, data) => { + if(err) return callback(err); + // making sure correct byte length + let byteLen = Buffer.alloc(8, data, 'hex'); + console.log(Buffer.byteLength(byteLen)); + // printing first 8 bytes in hex + return callback(console.log(file, Buffer.alloc(8, data, 'hex')), () => null); + }); +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..48e8e97 --- /dev/null +++ b/package.json @@ -0,0 +1,27 @@ +{ + "name": "03-parallel_file_system", + "version": "1.0.0", + "description": "![CF](https://camo.githubusercontent.com/70edab54bba80edb7493cad3135e9606781cbb6b/687474703a2f2f692e696d6775722e636f6d2f377635415363382e706e67) 04: Parallel File Processing ===", + "main": "index.js", + "directories": { + "test": "mocha" + }, + "devDependencies": { + "chai": "^4.1.0", + "mocha": "^3.4.2" + }, + "scripts": { + "test": "mocha" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/loganabsher/03-parallel_file_system.git" + }, + "keywords": [], + "author": "", + "license": "MIT", + "bugs": { + "url": "https://github.com/loganabsher/03-parallel_file_system/issues" + }, + "homepage": "https://github.com/loganabsher/03-parallel_file_system#readme" +} diff --git a/test/reader-test.js b/test/reader-test.js new file mode 100644 index 0000000..8aab919 --- /dev/null +++ b/test/reader-test.js @@ -0,0 +1,23 @@ +'use strict'; + +const expect = require('chai').expect; +const fr = require('../index.js'); + +describe('File Reader Module', () => { + describe('following proper file paths', () => { + it('should have working path \"__dirname\"/assets/file', (done) => { + fr.fileRunner((err) => { + expect(err).to.not.throw(); + done(); + }); + }); + }); + describe('logging in correct order', () => { + it('Should log one.txt then two.txt then three.txt', (done) => { + fr.fileRunner((err) => { + expect(err).to.equal('null'); + done(); + }); + }); + }); +});