@@ -33,7 +33,7 @@ function createFile (name, opts) {
33
33
var readers = [ ]
34
34
var writers = [ ]
35
35
36
- return ras ( { read, write, open, stat, close} )
36
+ return ras ( { read, write, open, stat, close, destroy } )
37
37
38
38
function read ( req ) {
39
39
const r = readers . pop ( ) || new ReadRequest ( readers , file , entry , mutex )
@@ -54,28 +54,53 @@ function createFile (name, opts) {
54
54
req . callback ( null , file )
55
55
}
56
56
57
+ function destroy ( req ) {
58
+ entry . remove ( ondone , onerror )
59
+
60
+ function ondone ( ) {
61
+ req . callback ( null , null )
62
+ }
63
+
64
+ function onerror ( err ) {
65
+ req . callback ( err , null )
66
+ }
67
+ }
68
+
57
69
function open ( req ) {
58
70
requestQuota ( maxSize , false , function ( err , granted ) {
59
71
if ( err ) return onerror ( err )
60
72
requestFileSystem ( window . PERSISTENT , granted , function ( res ) {
61
73
fs = res
62
- fs . root . getFile ( name , { create : true } , function ( e ) {
63
- entry = e
64
- entry . file ( function ( f ) {
65
- file = f
66
- req . callback ( null )
74
+ mkdir ( folder ( name ) , function ( ) {
75
+ fs . root . getFile ( name , { create : true } , function ( e ) {
76
+ entry = e
77
+ entry . file ( function ( f ) {
78
+ file = f
79
+ req . callback ( null )
80
+ } , onerror )
67
81
} , onerror )
68
- } , onerror )
82
+ } )
69
83
} , onerror )
70
84
} )
71
85
86
+ function mkdir ( name , ondone ) {
87
+ if ( ! name ) return ondone ( )
88
+ fs . root . getDirectory ( name , { create : true } , ondone , ondone )
89
+ }
90
+
72
91
function onerror ( err ) {
73
92
fs = file = entry = null
74
93
req . callback ( err )
75
94
}
76
95
}
77
96
}
78
97
98
+ function folder ( path ) {
99
+ const i = path . indexOf ( '/' )
100
+ const j = path . indexOf ( '\\' )
101
+ return path . slice ( 0 , Math . max ( 0 , i , j ) )
102
+ }
103
+
79
104
function WriteRequest ( pool , file , entry , mutex ) {
80
105
this . writer = null
81
106
this . entry = entry
0 commit comments