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
5 changes: 5 additions & 0 deletions lab-phelan-fred/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/node_modules/*
**/vendor/*
**/*.min.js
**/coverage/*
**/build/*
26 changes: 26 additions & 0 deletions lab-phelan-fred/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"env": {
"browser": true,
"node": true,
"commonjs": true,
"jest": true,
"es6": true
},
"globals": {
"err": true,
"req": true,
"res": true,
"next": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"no-console": "off",
"indent": [ "error", 2 ],
"quotes": ["error", "single", { "allowTemplateLiterals": true }],
"comma-dangle": ["error", "always-multiline"],
"semi": [ "error", "always" ]
}
}
80 changes: 80 additions & 0 deletions lab-phelan-fred/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@

# Created by https://www.gitignore.io/api/node,linux

### 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*

### 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


# End of https://www.gitignore.io/api/node,linux
Empty file added lab-phelan-fred/README.md
Empty file.
96 changes: 96 additions & 0 deletions lab-phelan-fred/__test__/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
const reader = require(`../lib/reader`);

describe(`Testing suite for reader.js`, () => {

describe('Testing reader.readTrio()', () => {

test(`+ : "Return first 25 chars of each three files"`, (done) => {
reader(
[`${__dirname}/../assets/ani.txt`,
`${__dirname}/../assets/nqu.txt`,
`${__dirname}/../assets/zzq.txt`,
],
(error,data) => {
expect(data).toEqual([
'anianiani anianiani anian',
'nqu uqn nqu uqn nqu uqn n',
'zzq_zzq_qzz____zzq_zzq_qz',
]);
done();
});
});

test(`- : "<paths> is not an array."`, () => {
expect (
() => {
reader(
'break <paths> : Not array',
(error,data)=>{return error, data;}
);
}
).toThrow();
});

test(`- : "<paths> length is wrong."`, () => {
expect (
() => {
reader(
[null, 'one','two','three','four', 0, null],
(error,data)=>{return error, data;}
);
}
).toThrow();
});

test(`- : "<paths> is not populated with strings."`, () => {
expect (
() => {
reader(
[1, 2, 3],
(error,data)=>{return error, data;}
);
}
).toThrow();
});

test(`- : "<paths> is not populated with strings."`, () => {
expect (
() => {
reader(
[1, 2, 3],
(error,data)=>{return error, data;}
);
}
).toThrow();
});

test(`- : "Callback failure: error in ReadFile callback."`, (done) => {
reader(
//Placed broken filenames here
[`${__dirname}/../assets/ani1.md`,
`${__dirname}/../assets/nqua.txt`,
`${__dirname}/../assets/asfasdfe.txt`,
],
(error) => {
expect(error).toBeTruthy();
done();
});
});

test(`- : "<paths> is not populated with strings."`, () => {
expect (
() => {
reader(
[`${__dirname}/../assets/ani.txt`,
`${__dirname}/../assets/nqu.txt`,
`${__dirname}/../assets/zzq.txt`,
],
'Breaking - this should be a function.'
);
}
).toThrow();
});

});

});
Binary file added lab-phelan-fred/assets/bitmap.bmp
Binary file not shown.
Binary file added lab-phelan-fred/assets/finger-print.bmp
Binary file not shown.
Binary file added lab-phelan-fred/assets/house.bmp
Binary file not shown.
Binary file added lab-phelan-fred/assets/non-palette-bitmap.bmp
Binary file not shown.
56 changes: 56 additions & 0 deletions lab-phelan-fred/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'use strict';

const fs = require('fs');
const greyscale = require('./lib/greyscale');
const invert = require('./lib/invert');
const brighten = require('./lib/brighten');

// Require all three transformation module JS files.

const CLIargs = process.argv.slice(2);

const inputPath = CLIargs[0];
const outputPath = CLIargs[1];
const transform = CLIargs[2];

const transforms = ['greyscale','invert','brighten'];

if ( //Check arguments for invalidity here, throw errors, (HOOK UP TESTS later).
typeof inputPath !== `string` ||
typeof outputPath !== `string` ||
typeof transform !== `string` ||
!transforms.includes(transform)
){
throw new Error('One or more CLI arguments are invalid. Please confirm that a Input Path, Output Path, and valid Transformation keyword are passed into the CLI.');
}

//Create the <File> constructor - which takes a buffer, and splits it out into the components which we need to modify (and those that don't), so that we can modify those we need to, then reassemble the entire file later. Will be used lower down in the code.
const File = (bufferIn) => {
this.headers = bufferIn;
this.colorTable = bufferIn;
this.remainder = bufferIn;
}; File;

//Start up the <fs.readFile> here - pass in the path argument, form the callback:
fs.readFile(inputPath, (error, data) => {
// >> <callback> recieves <error, data>. If error, throw error. If not, take the data (which is currently in Raw Buffer form), pass it into the <file> constructor, then, call the <module.function> which matches the <transform> argument passed into <index.js> from the CLI.

if (error) {throw error;}

var bitmap = new File(data);

switch (transform) {// (...See the mockup file for what the transform modules do...)
case 'greyscale': bitmap = greyscale(bitmap); break;
case 'invert' : bitmap = invert(bitmap); break;
case 'brighten' : bitmap = brighten(bitmap); break;
}

// >> <callback> then takes the data returned from the appropriate module function, and calls fs.WriteFile, passing in a path + '_<transform>' and the returned data, and forms a callback;
fs.WriteFile(outputPath, bitmap, (error) => {
// >> >> <callback> writes console.logs a friendly message: "BMP transform successful. New file at <new path>. Tranformation type: <transform>."
if (error) {throw error;}
console.log(`Bitmap "${transform}" transform successful.\nNew file at ${outputPath}.`);
});

// Once the fs.fileWrite operation's callback is finished, the program will close down.
} );
16 changes: 16 additions & 0 deletions lab-phelan-fred/lib/greyscale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

const greyscale = data => {

//With whatever kind of <split>, <map> <for loop>, or whatever other means which is easiest, cleanest, and most robust, modify the Color Palette byte ranges of the incoming <File> object to achieve the desired effect.

//Write all the byte ranges back into one buffer, and RETURN that buffer.

const buffer = 0;
buffer;

return data;

};

module.export(greyscale);
15 changes: 15 additions & 0 deletions lab-phelan-fred/lib/invert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

//require fs
//reset module.exports;

//const greyscale = (data) => {

//With whatever kind of <split>, <map> <for loop>, or whatever other means which is easiest, cleanest, and most robust, modify 1) the Color Palette byte ranges of the incoming <File> object.

//Research if there's anything else you need to modify. If so, modify those byte ranges here.

//Write all the byte ranges back into one buffer, and RETURN that buffer.
//}

//module.export this function.
15 changes: 15 additions & 0 deletions lab-phelan-fred/lib/nightmare.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

//require fs
//reset module.exports;

//const greyscale = (data) => {

//With whatever kind of <split>, <map> <for loop>, or whatever other means which is easiest, cleanest, and most robust, modify 1) the Color Palette byte ranges of the incoming <File> object.

//Research if there's anything else you need to modify. If so, modify those byte ranges here.

//Write all the byte ranges back into one buffer, and RETURN that buffer.
//}

//module.export this function.
Loading