PageSourceSearch

https://miniapp-tool.github.io/assets/README-BC5UC7Bx.js

js miniapp-tool.github.io collected 2026-10-03 09:37:02 UTC 10,175 bytes, 1 lines download raw bytes

1import{n as e,o as t,r as n}from"./app-DHdWsCsc.js";import{t as r}from"./plugin-vue_export-helper-BDNMzG2s.js";var i=JSON.parse(`{"path":"/file/","title":"@mptool/file","lang":"zh-CN","frontmatter":{"title":"@mptool/file","icon":"folder","description":"文件 API 提示 请注意,框架会自动帮你添加 USER_DATA_PATH 作为前缀,因此你无需关注它。 工具类 dirname(path: string): string 返回路径的文件夹部分 exists(path: string): boolean 返回布尔值,代表文件或文件夹是否存在 isDir(path: string): boolean ...","head":[["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"@mptool/file\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2026-10-03T04:31:00.000Z\\",\\"author\\":[{\\"@type\\":\\"Person\\",\\"name\\":\\"Mr.Hope\\",\\"url\\":\\"https://mister-hope.com\\"}]}"],["meta",{"property":"og:url","content":"https://miniapp-tool.github.io/file/"}],["meta",{"property":"og:site_name","content":"MP Tool"}],["meta",{"property":"og:title","content":"@mptool/file"}],["meta",{"property":"og:description","content":"文件 API 提示 请注意,框架会自动帮你添加 USER_DATA_PATH 作为前缀,因此你无需关注它。 工具类 dirname(path: string): string 返回路径的文件夹部分 exists(path: string): boolean 返回布尔值,代表文件或文件夹是否存在 isDir(path: string): boolean ..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"zh-CN"}],["meta",{"property":"og:updated_time","content":"2026-10-03T04:31:00.000Z"}],["meta",{"property":"article:modified_time","content":"2026-10-03T04:31:00.000Z"}]]},"git":{"createdTime":1791001860000,"updatedTime":1791001860000,"contributors":[{"name":"renovate[bot]","username":"renovate[bot]","email":"29139614+renovate[bot]@users.noreply.github.com","commits":2,"url":"https://github.com/renovate[bot]"}]},"readingTime":{"minutes":3.8,"words":1139},"filePathRelative":"file/README.md","autoDesc":true}`),a={name:`README.md`};function o(r,i,a,o,s,c){return t(),e(`div`,null,[...i[0]||=[n(`<h2 id="文件-api" tabindex="-1"><a class="header-anchor" href="#文件-api"><span>文件 API</span></a></h2><div class="hint-container tip"><p class="hint-container-title">提示</p><p>请注意,框架会自动帮你添加 <code>USER_DATA_PATH</code> 作为前缀,因此你无需关注它。</p></div><h3 id="工具类" tabindex="-1"><a class="header-anchor" href="#工具类"><span>工具类</span></a></h3><ul><li><p><code>dirname(path: string): string</code></p><p>返回路径的文件夹部分</p></li><li><p><code>exists(path: string): boolean</code></p><p>返回布尔值,代表文件或文件夹是否存在</p></li><li><p><code>isDir(path: string): boolean</code></p><p>返回布尔值,代表路径是否是文件夹</p></li><li><p><code>isFile(path: string): boolean</code></p><p>返回布尔值,代表路径是否是文件</p></li></ul><h2 id="读取类" tabindex="-1"><a class="header-anchor" href="#读取类"><span>读取类</span></a></h2><ul><li><p><code>ls(path: string): string[]</code></p><p>以数组形式列出目录下所有内容</p></li><li><p><code>readFile(path: string, encoding?: string): string | ArrayBuffer | undefined</code></p><p>读取指定路径的文件内容并返回。当文件不存在时,返回 <code>undefined</code>。</p><p><code>encoding</code> 为文件的编码格式,可选,默认 <code>&quot;utf-8&quot;</code></p></li><li><p><code>readJSON(path: string, encoding = &#39;utf-8&#39;): any | undefined</code></p><p>读取可序列化文件数据并返回解析结果。</p><p>当 JSON 文件不存在或解析失败时,返回 <code>undefined</code></p><ul><li><code>path</code>: 读取的文件路径,不应含有 <code>.json</code> 后缀</li><li><code>encoding</code>: 文件的编码格式,可选,默认 <code>utf-8</code></li></ul></li></ul><h3 id="操作类" tabindex="-1"><a class="header-anchor" href="#操作类"><span>操作类</span></a></h3><ul><li><p><code>mkdir(path: string, recursive = true): void</code></p><p>创建目录。第二个参数 <code>recursive</code> 可选,代表是否递归父目录,默认递归创建。</p></li><li><p><code>rm(path: string, type?: &quot;dir&quot; | &quot;file&quot;): void</code></p><p>删除指定路径。</p><p>第二个参数 <code>type</code> 是可选的,可填入 <code>&quot;dir&quot;</code> 或 <code>&quot;file&quot;</code>,填入可提升删除性能</p></li><li><p><code>writeFile(path: string, data: any, encoding?: string): void</code></p><p>写入文件</p><ul><li><code>path</code>: 待写入的文件路径,若文件或其父文件夹不存在会自动创建</li><li><code>data</code>: 待写入的数据,可接受任意可序列化的数据或 Buffer</li><li><code>encoding</code>: 文件编码选项,可选,默认 <code>utf-8</code> (数据) 或 <code>binary</code> (Buffer)</li></ul></li><li><p><code>
1writeJSON(path: string, data: any, encoding = &#39;utf-8&#39;): void</code></p><p>写入可序列化数据为 JSON</p><ul><li><code>path</code>: 写入文件的路径,若父文件夹不存在会自动创建</li><li><code>data</code>: 写入文件的数据,可接受任意可序列化的数据</li><li><code>encoding</code>: 文件编码选项,默认 <code>utf-8</code></li></ul></li><li><p><code>saveFile(tempFilePath: string, path: string): void</code></p><p>将缓存文件保存到本地文件存储。</p><ul><li><code>tempFilePath</code>: 缓存文件路径</li><li><code>path</code>: 保存文件路径</li></ul></li><li><p><code>saveOnlineFile(onlinePath: string, localPath: string): Promise&lt;string&gt;</code></p><p>将在线文件保存到本地指定位置,返回保存后的本地文件路径。</p><ul><li><code>onlinePath</code>: 在线文件路径</li><li><code>localPath</code>: 本地文件路径</li></ul><div class="hint-container tip"><p class="hint-container-title">提示</p><p>保存目录会自动创建。</p></div></li><li><p><code>unzip(zipFilePath: string, targetPath: string): Promise&lt;void&gt;</code></p><p>解压文件</p><ul><li><code>zipFilePath</code>: 待解压的压缩文件路径</li><li><code>targetPath</code>: 解压到的目录</li></ul><div class="hint-container tip"><p class="hint-container-title">提示</p><p>解压目录会自动创建。</p></div></li></ul><h2 id="存储-api" tabindex="-1"><a class="header-anchor" href="#存储-api"><span>存储 API</span></a></h2><h3 id="存取" tabindex="-1"><a class="header-anchor" href="#存取"><span>存取</span></a></h3><p><code>put</code> 和 <code>take</code> 可以存入任何数据,但存入的数据只能取出一次,且仅在当次小程序启动中有效。</p><div class="hint-container tip"><p class="hint-container-title">提示</p><p>为了保证性能,以及由于小程序对 <code>Function</code> 进行了特殊处理,我们不会对存入的数据进行深拷贝。</p></div><ul><li><p><code>put&lt;T = unknown&gt;(key: string, data: T): void</code>: 存数据。</p></li><li><p><code>take&lt;T = unknown&gt;(key: string): T | undefined</code>: 取数据</p><div class="hint-container tip"><p class="hint-container-title">提示</p><p>当数据已经被取过一次后,后续返回 <code>undefined</code>。</p></div></li></ul><h3 id="可持久化数据" tabindex="-1"><a class="header-anchor" href="#可持久化数据"><span>可持久化数据</span></a></h3><p><code>get</code> 和 <code>set</code> 设置的数据可持久化,且可以设置过期时间。</p><div class="hint-container warning"><p class="hint-container-title">注意</p><p>请注意由于微信小程序底层上的问题,自动清除只发生在下一次读取并发现已经失效时,如果你没有后续读取对应的存储,它们会一直保存 (即使已经过期)。</p><p>所以如果你使用了大量临时的键值去存入数据,你可能需要定期通过 <code>check</code> 手动检查并清除过期数据。</p></div><ul><li><p><code>set(key: string, value: any, expire?: number | &#39;once&#39; | &#39;keep&#39; = 0): void</code></p><p>同步设置数据。</p><ul><li><code>key</code>: 设置的键名</li><li><code>value</code>: 存入的值</li><li><code>expire</code>: 过期时间,可选,默认为 <code>0</code><ul><li><code>0</code>: 默认,永久有效</li><li><code>&#39;once&#39;</code>: 仅本次启动有效</li><li><code>&#39;keep&#39;</code>: 表示保持上一次有效时间</li><li>数字: 以毫秒为单位的有效时间</li></ul></li></ul><div class="hint-container tip"><p class="hint-container-title">提示</p><p>请注意,如果传入 <code>&#39;keep&#39;</code> 时,存储中不存在同名键值,则该值也不会被写入。</p></div></li><li><p><code>setAsync(key: string, value: any, expire?: number | &#39;once&#39; | &#39;keep&#39; = &#39;once&#39;): Promise&lt;void&gt;</code></p><p><code>set</code> 的异步版本,在设置大量数据时可考虑使用,返回一个 Promise。</p></li><li><p><code>get&lt;T = unknown&gt;(key: string): T | undefined</code></p><p>同步读取数据并返回。</p><p>当数据已经过期时,返回 <code>undefined</code>。</p><ul><li><code>key</code>: 设置的键名</li></ul></li><li><p><code>getAsync&lt;T = unknown&gt;(key: string): Promise&lt;T | undefined&gt;</code></p><p><code>get</code> 的异步版本,在读取大量数据避免阻塞线程时可考虑使用,返回一个 Promise。</p><ul><li><code>key</code>: 设置的键名</li></ul></li><li><p><code>remove(key: string): void</code></p><p>同步删除数据。</p><ul><li><code>key</code>: 删除的键名</li></ul></li><li><p><code>removeAsync(key: string): Promise&lt;void&gt;</code></p><p>异步删除数据,返回一个 Promise。</p><ul><li><code>key</code>: 删除的键名</li></ul></li><li><p><code>check(): void</code></p><p>同步检查并清理过期数据。</p></li><li><p><code>checkAsync(): Promise&lt;void&gt;</code></p><p>异步检查并清理过期数据,返回一个 Promise。</p></li></ul>`,17)]])}var s=r(a,[[`render`,o]]);
1export{i as _pageData,s as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.