UNPKG

1.02 kBJavaScriptView Raw
1/**
2 * Artycles - Local Store
3 * - Saving media locally
4**/
5
6var fs = require("fs"),
7 path = require("path"),
8 utils = require("../lib/utils");
9
10// constructor
11var Model = function( options ){
12
13 // no store is expected for this model
14 //this.store = options.store;
15 // save other options
16 //delete options.store;
17 this.options = options;
18
19}
20
21Model.prototype = {
22
23 constructor: Model,
24
25 create: function( data, callback ){
26 // support loop of multiple files?
27 // make sure destination folder exists
28 var dir = path.dirname( data.destination );
29 if ( !fs.existsSync( dir ) ) utils.mkdir( dir );
30 //
31 fs.createReadStream( data.source ).pipe( fs.createWriteStream( data.destination ) )
32 .on("finish", function(){
33 // error control?
34 callback(true);
35 });
36 },
37
38 read: function( file, callback ){
39 var source = this.options.path + file;
40 return fs.createReadStream( source ).pipe();
41 },
42
43 update: function( query, callback ){
44 // tba
45 },
46
47 destroy: function( item, callback ){
48 // tba
49 }
50
51}
52
53
54module.exports = Model;
\No newline at end of file