Skip to content

Commit 3d3e732

Browse files
save file
1 parent a9b6617 commit 3d3e732

1 file changed

Lines changed: 195 additions & 1 deletion

File tree

utils/misc/nodejs-terminal/html/webcontainer-fs/webcontainer-fs.html

Lines changed: 195 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@
9494

9595

9696

97-
var btn = {};
97+
var btn = {};
98+
var file = {};
99+
var dir = {};
98100

99101

100102
//:
@@ -216,9 +218,201 @@
216218
}//read
217219

218220

221+
//:
222+
223+
224+
file.click = function(path,filename){
225+
debug('file.click',path,filename);
226+
}//click
227+
228+
229+
file.dblclick = function(path,filename){
230+
debug('file.dblclick',path,filename);
231+
var url = ui.url.value;
232+
load.ui(url,path,filename);
233+
234+
}//dblclick
235+
236+
237+
238+
file.add = async function(path,name){
239+
debug('file.add',path,name);
240+
var abs = path+name;
241+
debug(abs);
242+
await webcontainer.fs.writeFile(abs,'');
243+
return false;
244+
245+
}//add
246+
247+
248+
file.rem = async function(path,name){
249+
debug('file.rem',path,name);
250+
var abs = path+name;
251+
debug(abs);
252+
await webcontainer.fs.rm(abs);
253+
254+
return false;
255+
256+
}//rem
257+
258+
259+
file.upload = async function(path,name,blob){
260+
debug('file.upload',path,name,blob);
261+
var abs = path+name;
262+
263+
var buf = await blob.arrayBuffer();
264+
var uint8 = new Uint8Array(buf);
265+
await wc.fs.writeFile(path,uint8);
266+
267+
return false;
268+
269+
}//upload
270+
271+
272+
file.download = async function(path){
273+
274+
var abs = prefix+path;
275+
276+
if(status){
277+
log.red(status);
278+
return;
279+
}
280+
281+
var file = await db.open(abs);
282+
var blob = await file.read();
283+
file.close();
284+
return {result:false,blob};
285+
286+
}//download
287+
288+
289+
290+
219291

220292

221293

294+
295+
//:
296+
297+
298+
299+
300+
dir.parent = function(){
301+
302+
if(status){
303+
log.red(status);
304+
return;
305+
}
306+
307+
}//parent
308+
309+
310+
dir.add = async function(path,name){
311+
debug('dir.add',path,name);
312+
var abs = prefix+path+name+'/';
313+
debug(abs);
314+
if(status){
315+
log.red(status);
316+
return;
317+
}
318+
319+
var file = await db.open(abs);
320+
file.close();
321+
return false;
322+
323+
}//add
324+
325+
326+
dir.rem = async function(path,name){
327+
debug('dir.rem',path,name);
328+
var abs = prefix+path+name;
329+
330+
if(status){
331+
log.red(status);
332+
return;
333+
}
334+
335+
var {names:list} = await db.list(abs);
336+
337+
var n = list.length;
338+
for(var i=0;i<n;i++){
339+
340+
var fn = list[i];
341+
var result = await db.delete(fn);
342+
343+
}//for
344+
345+
return false;
346+
347+
}//rem
348+
349+
350+
dir.clear = async function(path){
351+
debug('dir.clear',path);
352+
var abs = prefix+path;
353+
354+
if(status){
355+
log.red(status);
356+
return;
357+
}
358+
359+
var {names:list} = await db.list(abs);
360+
361+
var n = list.length;
362+
for(var i=0;i<n;i++){
363+
364+
var fn = list[i];
365+
if(fn.length>abs.length){
366+
var result = await db.delete(fn);
367+
}
368+
369+
}//for
370+
371+
return false;
372+
373+
}//clear
374+
375+
376+
dir.read = read;
377+
378+
379+
dir.dblclick = function(path,name){
380+
debug('dir.dblclick',path,name);
381+
if(status){
382+
log.red(status);
383+
return;
384+
}
385+
386+
read(path+name);
387+
return false;
388+
389+
}//dblclick
390+
391+
392+
393+
//:
394+
395+
396+
397+
398+
399+
400+
401+
402+
403+
404+
405+
406+
407+
408+
409+
410+
411+
412+
413+
414+
415+
222416
/*
223417
224418
// create folder

0 commit comments

Comments
 (0)