@@ -22,7 +22,7 @@ class FileStore extends DataStore {
2222
2323 this . directory = options . directory || options . path . replace ( / ^ \/ / , '' ) ;
2424
25- this . extensions = [ 'creation' ] ;
25+ this . extensions = [ 'creation' , 'creation-defer-length' ] ;
2626 this . database = new Configstore ( `${ pkg . name } -${ pkg . version } ` ) ;
2727 this . _checkOrCreateDirectory ( ) ;
2828 }
@@ -53,7 +53,7 @@ class FileStore extends DataStore {
5353 return reject ( err ) ;
5454 }
5555
56- this . database . set ( ` ${ file . id } .upload_length` , file . upload_length ) ;
56+ this . database . set ( file . id , file ) ;
5757
5858 return fs . close ( fd , ( exception ) => {
5959 if ( exception ) {
@@ -70,13 +70,13 @@ class FileStore extends DataStore {
7070 * Write to the file, starting at the provided offset
7171 *
7272 * @param {object } req http.incomingMessage
73- * @param {string } file_name Name of file
73+ * @param {string } file_id Name of file
7474 * @param {integer } offset starting offset
7575 * @return {Promise }
7676 */
77- write ( req , file_name , offset ) {
77+ write ( req , file_id , offset ) {
7878 return new Promise ( ( resolve , reject ) => {
79- const path = `${ this . directory } /${ file_name } ` ;
79+ const path = `${ this . directory } /${ file_id } ` ;
8080 const options = {
8181 flags : 'r+' ,
8282 start : offset ,
@@ -112,16 +112,16 @@ class FileStore extends DataStore {
112112 /**
113113 * Return file stats, if they exits
114114 *
115- * @param {string } file_name name of the file
115+ * @param {string } file_id name of the file
116116 * @return {object } fs stats
117117 */
118- getOffset ( file_name ) {
119- const db_record = this . database . get ( file_name ) ;
118+ getOffset ( file_id ) {
119+ const db_record = this . database . get ( file_id ) ;
120120 return new Promise ( ( resolve , reject ) => {
121- const file_path = `${ this . directory } /${ file_name } ` ;
121+ const file_path = `${ this . directory } /${ file_id } ` ;
122122 fs . stat ( file_path , ( error , stats ) => {
123123 if ( error && error . code === FILE_DOESNT_EXIST && db_record ) {
124- console . warn ( `[FileStore] getOffset: No file found at ${ file_path } but db record exists ${ db_record . toString ( ) } ` ) ;
124+ console . warn ( `[FileStore] getOffset: No file found at ${ file_path } but db record exists` , db_record ) ;
125125 return reject ( 410 ) ;
126126 }
127127
@@ -134,8 +134,12 @@ class FileStore extends DataStore {
134134 console . warn ( error ) ;
135135 return reject ( error ) ;
136136 }
137- stats . upload_length = this . database . get ( `${ file_name } .upload_length` ) ;
138- return resolve ( stats ) ;
137+
138+ return resolve ( {
139+ size : stats . size ,
140+ upload_length : db_record . upload_length ,
141+ upload_defer_length : db_record . upload_defer_length ,
142+ } ) ;
139143 } ) ;
140144 } ) ;
141145 }
0 commit comments