@ firecrawl/ anydoc-wasm (英语)
网页大会装订 任何文件,加上演示页的源 fircrawl.github.io/anydoc (英语)。 。 。 .
API 镜像 Rust 库, 减去路径 to_markdown: wasm没有文件系统,所以转换总是从字节开始.
npm install @firecrawl/anydoc-wasm
import init, {
formatFromBytes,
toMarkdownBytes,
toDocument,
} from '@firecrawl/anydoc-wasm';
await init();
// With the format detected from the content:
const markdown = toMarkdownBytes(bytes);
// Or name it, which signature-less formats (CSV) need:
const fromCsv = toMarkdownBytes(bytes, 'csv');
// Or stop at the document model, which also carries embedded assets:
const document = toDocument(bytes);
// Format detection on its own:
formatFromBytes(bytes); // 'docx', or undefined when nothing matches
软件包由 wasm-pack --target web: 装入平原 <script type="module"> 与处理 new URL(..., import.meta.url) 资产模式(Vite,webpack 5, Rollup). 在节点中,将模块字节传递到 initSync 而不是打电话 init (见 test.mjs) (中文(简体) ).
呼叫是同步的:在呼叫线条上被被wim运行单行跑,所以如果主线条必须保持响应,就转换到工人身上.
错误
转换只有在没有完整的Markdown出字节时才会抛出. 抛出值是一个 Error 谁 code 出错的地方:
try {
return toMarkdownBytes(bytes);
} catch (error) {
// No document comes out of these, so record the file and take the next one.
if (error.code === 'encrypted' || error.code === 'unsupported') {
unconverted.push({ name, reason: error.code });
return null;
}
throw error;
}
code | 含义 |
|---|---|
unsupported | 未知格式, 或无法转换的格式 |
needsOcr | PDF的页数是扫描的,或只图像; pages 给他们起名 |
malformed | 结构上无法使用:无法提取有意义的内容 |
encrypted | 加密或密码保护 |
resourceLimit | 跨越了固定的安全限制(减压、筑巢、节点计数) |
missingPart | 缺少任何有意义的产出所需的部分 |
error.message 带有细节,将软件包部分命名为格式识别错误部分。 TypeScript 将联盟变为 ConvertErrorCode这个箱子 io 这里没有对应代码: 没有文件系统可以读取 .
大楼
wasm-pack build wasm --release --target web --scope firecrawl
node --test wasm/test.mjs
这将生成 npm 包在 wasm/pkg/:模块,JS胶,和TypeScript定义. 出版来源 ../.github/workflows/release.yml 在释放标签.
演示页
www/ 持有静态演示站点,该演示站点从 www/pkg/创建该目录,然后服务 www/数字 :
wasm-pack build wasm --release --target web --no-pack --out-dir www/pkg
python -m http.server -d wasm/www
../.github/workflows/pages.yml 在每次向主推上,都构建和部署相同的布局到 GitHub Pages.