TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Using files with browsers, in reality

73 点作者 jamghee大约 3 年前

9 条评论

ohCh6zos大约 3 年前
Should web pages have this kind of API? We seem to be repeating the mistakes of activeX but this time with JavaScript.
评论 #30757374 未加载
评论 #30760141 未加载
评论 #30757598 未加载
评论 #30756775 未加载
dugmartin大约 3 年前
Another interesting use of the File System Access API (<a href="https:&#x2F;&#x2F;caniuse.com&#x2F;?search=File%20System%20Access%20API" rel="nofollow">https:&#x2F;&#x2F;caniuse.com&#x2F;?search=File%20System%20Access%20API</a>) is:<p><a href="https:&#x2F;&#x2F;vscode.dev&#x2F;" rel="nofollow">https:&#x2F;&#x2F;vscode.dev&#x2F;</a><p>You can grant it access to a directory on your local machine and then edit files like you would in the Electron version.
brundolf大约 3 年前
I wonder how this API will affect Electron apps once it&#x27;s available there. For some apps the only reason you need non-UI code at all is for working with the file system; seems like it would be great to be able to consolidate more logic into the UI process
shuntress大约 3 年前
I find the way we are slowly converging on Chromium-Powered-Browser as the standard operating system to be both funny and frustrating.<p>I&#x27;m really dissatisfied with Electron apps in general and using an an operating system designed to run on top of other operating systems <i>feels</i> wrong.<p>But, I do really like it when things portably <i>just work</i>.
评论 #30764588 未加载
slaymaker1907大约 3 年前
It&#x27;s not terrible, but it still has a lot of warts. I wrote a saver plugin for Tiddlywiki that uses this API for a self modifying HTML file. <a href="https:&#x2F;&#x2F;slaymaker1907.github.io&#x2F;tiddlywiki&#x2F;plugin-library.html" rel="nofollow">https:&#x2F;&#x2F;slaymaker1907.github.io&#x2F;tiddlywiki&#x2F;plugin-library.ht...</a><p>One major annoyance is that you can&#x27;t just show the file picker for &quot;security reasons&quot;, it has to be user prompted. This is a useless precaution because you can just add an onclick handler to the document body. It inconveniences non-malware developers while hardly troubling malicious sites at all.<p>Another goodie is that resolving a path is extremely expensive with no opportunity for caching from the OS. You have to parse paths yourself and individually walk each directory.<p>I&#x27;ve also been working on an equivalent API to the fs module in Node lately, but really such an API should have been the #1 priority example for using this API. It would have immediately highlighted how difficult the path problem is. OS&#x2F;browser engine nerds deal with file descriptors, but most applications work with paths.<p>It also would be great if Firefox would stop being so hostile to this API. The API has problems, but they aren&#x27;t inherent to the goals of this API. I also find polyfills for this API to be ridiculous. You really can&#x27;t polyfill this in a meaningful way for the browser because it is so groundbreaking. Having a non-Google implementation of the API would be way more helpful than polyfills.
ShamelessC大约 3 年前
&gt; Google’s documentation and the specification itself contained this bug in example code.<p>Off-topic, but Google&#x27;s documentation for _everything_ contains subtle bugs such as this.
mattdesl大约 3 年前
Nice article! It’s a great API, hope to see the kinks ironed out.<p>I am using it to stream PNG frames in real-time into a user’s file system, for web-based media tools. This allows the user to generate their own HD video files offline at maximum quality, bringing static web a little closer to pro level media tooling.<p>One downside aside from browser support is that two permissions must be requested for this: one to select the directory to save to, and then again to give write access.
nyanpasu64大约 3 年前
As a native programmer who meddles with the horrors of thread safety and &amp; and &amp;mut, and occasionally dabbles in high-level (JS&#x2F;Dart) asynchronity, async functions fill me with much of the same fear and caution. await looks like merely a nonblocking function call, but means arbitrary code executes and can and will mutate arbitrary state under your feet. Shared state across coroutines is nearly as dangerous as shared state across threads, and (I conjecture) far more pervasive.<p>In the code in question (<a href="https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20220113153505&#x2F;https:&#x2F;&#x2F;web.dev&#x2F;file-system-access&#x2F;#drag-and-drop-integration" rel="nofollow">https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20220113153505&#x2F;https:&#x2F;&#x2F;web.dev&#x2F;f...</a>, now changed in <a href="https:&#x2F;&#x2F;web.dev&#x2F;file-system-access&#x2F;#drag-and-drop-integration" rel="nofollow">https:&#x2F;&#x2F;web.dev&#x2F;file-system-access&#x2F;#drag-and-drop-integratio...</a>):<p><pre><code> elem.addEventListener(&#x27;drop&#x27;, async (e) =&gt; { &#x2F;&#x2F; Prevent navigation. e.preventDefault(); &#x2F;&#x2F; Process all of the items. for (const item of e.dataTransfer.items) { &#x2F;&#x2F; Careful: `kind` will be &#x27;file&#x27; for both file &#x2F;&#x2F; _and_ directory entries. if (item.kind === &#x27;file&#x27;) { const entry = await item.getAsFileSystemHandle(); if (entry.kind === &#x27;directory&#x27;) { handleDirectoryEntry(entry); } else { handleFileEntry(entry); } } } }); </code></pre> I probably wouldn&#x27;t have guessed that `e.dataTransfer.items` gets cleared at the first await (since I&#x27;m not a proficient web developer), but I would&#x27;ve been <i>extremely</i> wary of this code in general. Additionally (not tied to async-await but race conditions in general), is `item.getAsFileSystemHandle()` a TOCTTOU vulnerability where the type of an item can change between folders and files and symlinks etc., while this code is running?<p>Rust&#x27;s &amp; vs. &amp;mut system largely eliminates shared state hazards in both threading and asynchronity (&amp;mut is exclusive&#x2F;unaliased and can&#x27;t be mutated by other threads or event loop jobs, and &amp; is difficult and unidiomatic to mutate), though it doesn&#x27;t solve async cancellation errors (<a href="https:&#x2F;&#x2F;carllerche.com&#x2F;2021&#x2F;06&#x2F;17&#x2F;six-ways-to-make-async-rust-easier&#x2F;" rel="nofollow">https:&#x2F;&#x2F;carllerche.com&#x2F;2021&#x2F;06&#x2F;17&#x2F;six-ways-to-make-async-rus...</a>, discussed at <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=27542504" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=27542504</a>), or filesystem TOCTTOU (<a href="https:&#x2F;&#x2F;blog.rust-lang.org&#x2F;2022&#x2F;01&#x2F;20&#x2F;cve-2022-21658.html" rel="nofollow">https:&#x2F;&#x2F;blog.rust-lang.org&#x2F;2022&#x2F;01&#x2F;20&#x2F;cve-2022-21658.html</a> as well as user code).<p>Qt event loop reentrancy is fun(tm) as well. It looks like a blocking call, but spawns a nested event loop which can do anything (but rarely enough to lull you into a false sense of complacency), resulting in segfaults like <a href="https:&#x2F;&#x2F;github.com&#x2F;Nheko-Reborn&#x2F;nheko&#x2F;issues&#x2F;656" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Nheko-Reborn&#x2F;nheko&#x2F;issues&#x2F;656</a> (workaround at <a href="https:&#x2F;&#x2F;github.com&#x2F;Nheko-Reborn&#x2F;nheko&#x2F;commit&#x2F;570d00b000bd558592af317746fa3639fb022fa4" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Nheko-Reborn&#x2F;nheko&#x2F;commit&#x2F;570d00b000bd558...</a>, I didn&#x27;t look into it). And Qt lacks &quot;easy&quot; await syntax and a framework based on calling red functions (though I didn&#x27;t look into C++20 coroutines yet, perhaps <a href="https:&#x2F;&#x2F;www.qt.io&#x2F;blog&#x2F;asynchronous-apis-in-qt-6" rel="nofollow">https:&#x2F;&#x2F;www.qt.io&#x2F;blog&#x2F;asynchronous-apis-in-qt-6</a> or <a href="https:&#x2F;&#x2F;github.com&#x2F;mhogomchungu&#x2F;tasks" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;mhogomchungu&#x2F;tasks</a> or <a href="https:&#x2F;&#x2F;blog.blackquill.cc&#x2F;asynchronous-qtquick-uis-and-their-implementation-the-toolbox#thennables" rel="nofollow">https:&#x2F;&#x2F;blog.blackquill.cc&#x2F;asynchronous-qtquick-uis-and-thei...</a>?).
评论 #30762076 未加载
PaulHoule大约 3 年前
Other APIs for async file I&#x2F;O are outright painful.