I have class File that is in charge of managing files.
Class File {
constructor(path) {
this.path = path;
}
clean() {
// remove file
},
zip() {
// Create a zip archive with the file
}
}
This module only take the absolute path of the file.
The problem is I also need methods to fetch and insert this files into DB (I use S3).
I see 2 solutions on how to design this:
I create a DAO module that is in charge of sending or fetching files from the DB.
fileDao.fetch(1, function(err, res) {
var file = new File(res.path);
// Actions on this file
fileDao.send(file.path);
});
I compose my File Class with DB access methods
var file = new File();
file.fetch(1, function(err, res) {
file.path; // absolute path of the file
// actions on the file
file.send();
});
The problem is, file Object can either be instantiated with the path (if the file is already on my file system) or by fetching it from Database.
How would you design this, maybe pattern already exist in order to manage files.
Best regards.
via Simon Bruneaud
No comments:
Post a Comment