Files
SnowLuma/.pnpm-store/v11/files/25/a2f259d73a497be6065197b985b716486c8d0e6940ccee8254be24a18585fb356d8a12f94675b2ec8b5776192cdc4267b827a867d48d2c3abb3c4d148c2b97
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

51 lines
1.1 KiB
Plaintext

import type { SerovalNode } from 'seroval';
import { createPlugin } from 'seroval';
type FileNode = {
name: SerovalNode;
options: SerovalNode;
buffer: SerovalNode;
};
const FilePlugin = /* @__PURE__ */ createPlugin<File, FileNode>({
tag: 'seroval-plugins/web/File',
test(value) {
if (typeof File === 'undefined') {
return false;
}
return value instanceof File;
},
parse: {
async async(value, ctx) {
return {
name: await ctx.parse(value.name),
options: await ctx.parse({
type: value.type,
lastModified: value.lastModified,
}),
buffer: await ctx.parse(await value.arrayBuffer()),
};
},
},
serialize(node, ctx) {
return (
'new File([' +
ctx.serialize(node.buffer) +
'],' +
ctx.serialize(node.name) +
',' +
ctx.serialize(node.options) +
')'
);
},
deserialize(node, ctx) {
return new File(
[ctx.deserialize(node.buffer) as ArrayBuffer],
ctx.deserialize(node.name) as string,
ctx.deserialize(node.options) as FilePropertyBag,
);
},
});
export default FilePlugin;