FCC-Project_File-Metadata/scripts/file-management/analyze.js

35 lines
No EOL
767 B
JavaScript

const MetadataExtractor = class {
/*
* MetadataExtractor class
* This class is used to extract metadata from a BLOB object.
*/
constructor(BLOB) {
this.blob = BLOB;
this.extract([`fieldname`, `encoding`, `originalname`, `mimetype`, `size`]);
}
/*
* Extract data from the blob.
*/
extract(FIELDS) {
// Verify the validity of the blob.
if (!this.blob) {
throw new Error("Invalid BLOB object");
};
// Extract the relevant fields.
let RESPONSE = {};
FIELDS.forEach((FIELD) => {
if (!(this.blob[FIELD] === undefined)) {
this[FIELD] = this.blob[FIELD];
RESPONSE[FIELD] = this.blob[FIELD];
}
});
// Return the response.
return (RESPONSE);
}
}
module.exports = MetadataExtractor;