Skip to content

Commit 155b89e

Browse files
save file
1 parent d585226 commit 155b89e

File tree

1 file changed

+235
-35
lines changed

1 file changed

+235
-35
lines changed

code/nodejs/servers/file-server/file-server.html

Lines changed: 235 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,241 @@
11

22

33

4-
5-
6-
7-
8-
9-
10-
11-
12-
13-
14-
15-
This code module implements a lightweight HTTPS server that exposes direct file system operations to the browser through a simple fetch‑based API. By sending requests such as
16-
17-
js
18-
fetch("https://localhost:3000/a.txt", { headers: { mode: "load" } })
19-
the browser can interact with local files securely and consistently.
20-
21-
Supported operations include:
22-
23-
load → retrieve file contents
24-
25-
save → write or overwrite file data
26-
27-
file delete → remove a file
28-
29-
dir read → list directory contents
30-
31-
dir create → make a new directory
32-
33-
dir delete → remove a directory
34-
35-
Together, these commands provide a complete set of standard file I/O capabilities accessible from the browser. This member sits at the Code stage of the pipeline: more substantial than a library, since it defines a working server with a defined protocol, but not yet a full project. It serves as a foundation for building browser‑driven file management tools, developer utilities, or experimental web‑native applications.
36-
37-
38-
4+
<!DOCTYPE html>
5+
6+
<html lang=en>
7+
8+
<head>
9+
<meta charset=utf-8>
10+
11+
<title>
12+
file-server
13+
</title>
14+
15+
<meta name=description content=''>
16+
17+
<base href='https://ext-code.com/code/nodejs/servers/file-server/'>
18+
<link rel=canonical href='https://ext-code.com/code/nodejs/servers/file-server/file-server.html'>
19+
20+
<meta name=viewport content='width=device-width, initial-scale=1'>
21+
<link rel=icon href='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAMAAAAM7l6QAAABAlBMVEVHcEzwShbtTxrzbhXyoSHyORLyTRPzXxTzZxXzqB/upCjyRRP0ixfpOB31qBnyTxTvOBTtMBX1nhjxLBH1phr0nhvwMBPtNxb0hhfubRzzeBbyaxjxbBr0jBr0hRnyQhP0jhfzlBzzrB70gxbxPRP0kxjypiD0rBz0mRnzox/uKhLzfhjzoR3xPRPzmRn0kxjvKhPwMhL1oxnwMxP1oxryWBXyeRnxXRfzfRbyfhryVxXycxfybRjwchrzbRXxeBnyaRjzchbyYxbzYhXxXxfzaBbtKxTuKhP0qx3zrB7xZhrxZhn1pRjxMBHzUhPyRRP0jhf0iBf0kxf1mRj0gxb0fRW9Ofp/AAAATHRSTlMAHxH+EP3g/f42CIF/CPZ/izb89ruLuyjgG/x/Ux8f3+AeWoDO3yB4ziV4eyuzs4JL6+vQ0HtYWOUk5dGMRfFnjOjR6GjxWlpLS0VFZBEF4QAAATVJREFUKM+tk9eygjAURaWJoFgREOy9997rrYD9/3/lwsCEBJ/ujDztlcXsk4TB43nHg3frH5wVuc96F0dtRIhpsYidjShEYCsONK0nYBZgQk/TBiKkwxQVFkEhLpoMDS5SLQ5u41pU0RmPZc5+dC/+cwZztPdVe2Gth1Ad0v+h5/oI1SN97ugjTU9QPaHpo32qX+VA7xOoTuzpg/Jjnm3r8/lOSfc3SJ6M5a0RlgRBrF/12lhemuUrZUcs3OULYqes7IvbyPIY1WNZ3gCYTZ8NVDee0xmAtPQooLrwkNIAUtI1gOrAFdbZi1tfsikAudKtg+rOrZQDQFbvbRa2bPteJR2MR6PxJmCyaTL0dm2oqn2+bEGZ76vqsAa3MXxQDTJ2NiLPoHshvyp5ezybr3yTb/m3/gB3/SLZj0tcfgAAAABJRU5ErkJggg=='>
22+
23+
<script src='https://libs.ext-code.com/js/dom/component/component.js'></script>
24+
<script src='https://libs.ext-code.com/js/dom/init-hdr/init-hdr.js'></script>
25+
26+
<script>
27+
28+
29+
function start(){
30+
debug('start');
31+
initdom();
32+
33+
}//start
34+
35+
36+
</script>
37+
38+
<style>
39+
40+
html
41+
{font-family:arial}
42+
43+
44+
#hdr
45+
{display:flex;justify-content:space-between}
46+
#hdr>div:first-of-type
47+
{display:flex;gap:20px}
48+
49+
code
50+
{display:block;white-space:pre;font-family:monospace;margin:20px;padding:20px;background:whitesmoke}
51+
52+
53+
54+
web-editor
55+
{display:block;height:200px;margin:20px;border:1px solid lightgray;padding:10px}
56+
57+
58+
input
59+
{font-size:16px;padding:5px 10px}
60+
input[type=button]
61+
{cursor:pointer}
62+
63+
64+
</style>
65+
66+
</head>
67+
68+
69+
<body>
70+
71+
72+
<div id=hdr>
73+
74+
<div>
75+
<a href='https://ext-code.com/'>
76+
home
77+
</a>
78+
79+
<a href='../../code.html'>
80+
code
81+
</a>
82+
</div>
83+
84+
<h1>
85+
file-server
86+
</h1>
87+
88+
<div>
89+
19 Dec 2025
90+
</div>
91+
92+
</div hdr>
93+
94+
95+
<div>
96+
97+
98+
<p>
99+
This code module implements a lightweight HTTPS server that exposes direct file system operations to the browser through a simple fetch‑based API. By sending requests such as
100+
</p>
101+
102+
<div>
103+
<input value=download type=button>
104+
</div>
105+
106+
<code>
107+
108+
fetch("https://localhost:3000/a.txt", { headers: { mode: "load" } })
109+
110+
</code>
111+
112+
<p>
113+
the browser can interact with local files securely and consistently.
114+
</p>
115+
116+
<p>
117+
Supported operations include:
118+
</p>
119+
120+
<p>
121+
load → retrieve file contents
122+
</p>
123+
124+
<p>
125+
save → write or overwrite file data
126+
</p>
127+
128+
<p>
129+
file delete → remove a file
130+
</p>
131+
132+
<p>
133+
dir read → list directory contents
134+
</p>
135+
136+
<p>
137+
dir create → make a new directory
138+
</p>
139+
140+
<p>
141+
dir delete → remove a directory
142+
</p>
143+
144+
<p>
145+
Together, these commands provide a complete set of standard file I/O capabilities accessible from the browser. This member sits at the Code stage of the pipeline: more substantial than a library, since it defines a working server with a defined protocol, but not yet a full project. It serves as a foundation for building browser‑driven file management tools, developer utilities, or experimental web‑native applications.
146+
</p>
147+
148+
</div>
149+
150+
<web-editor component h=200>
151+
152+
[ not implemented yet ]
153+
154+
</web-editor>
155+
156+
<div>
157+
158+
<p>
159+
the client side library can found at
160+
</p>
161+
162+
</div>
163+
164+
<div>
165+
166+
<a href='/libs/js/io/file-server/file-server.html'>
167+
file-server
168+
<span class=link-domain>
169+
ext-code.com
170+
</span>
171+
</a>
172+
173+
</div>
174+
175+
176+
177+
</body>
178+
179+
<script>
180+
181+
182+
var jszip;
183+
184+
185+
var btn = {};
186+
187+
188+
//:
189+
190+
191+
function initdom(){
192+
193+
$('[value=download]').onclick = btn.download;
194+
195+
}//initdom
196+
197+
198+
//:
199+
200+
201+
btn.download = async function(){
202+
203+
if(!jszip){
204+
jszip = await import('https://cdn.jsdelivr.net/npm/jszip/+esm');
205+
jszip = jszip.default;
206+
}
207+
208+
var zip = new jszip();
209+
zip.folder(`file-server`);
210+
211+
var res = await fetch('https://raw.githubusercontent.com/javascript-2020/code/main/nodejs/server/file-server/file-server.js');
212+
var blob = await res.blob();
213+
zip.file(`file-server/file-server.js`,blob);
214+
215+
zip.folder(`file-server/node_modules`);
216+
217+
var res = await fetch('https://raw.githubusercontent.com/javascript-2020/libs/main/js/string/getmime/getmime.js');
218+
var blob = await res.blob();
219+
zip.file(`file-server/node_modules/getmime.js`,blob);
220+
221+
var res = await fetch('https://raw.githubusercontent.com/javascript-2020/libs/main/nodejs/keys/keys.js');
222+
var blob = await res.blob();
223+
zip.file(`file-server/node_modules/keys.js`,blob);
224+
225+
var blob = await zip.generateAsync({type:'blob'});
226+
227+
var url = window.URL.createObjectURL(blob);
228+
var a = document.createElement('a');
229+
a.download = 'file-server';
230+
a.href = url;
231+
a.click();
232+
233+
}//download
234+
235+
236+
</script>
237+
238+
</html>
39239

40240

41241

0 commit comments

Comments
 (0)