import { join, basename } from "https://deno.land/std/path/mod.ts";
import { readLines } from "https://deno.land/std/io/mod.ts";
import { format } from "https://deno.land/std/datetime/mod.ts";
async function processPath(path) {
console.log(`处理路径: ${path}`);
const fileName = basename(path);
console.log(`文件名: ${fileName}`);
const fullPath = join("/tmp", fileName);
console.log(`完整路径: ${fullPath}`);
const now = new Date();
const formattedDate = format(now, "yyyy-MM-dd HH:mm:ss");
console.log(`当前时间: ${formattedDate}`);
return {
originalPath: path,
fileName: fileName,
fullPath: fullPath,
timestamp: formattedDate
};
}
async function simulateFileReading() {
const text = `这是第一行
这是第二行
这是第三行
这是最后一行`;
const encoder = new TextEncoder();
const decoder = new TextDecoder();
const data = encoder.encode(text);
const stream = new ReadableStream({
start(controller) {
controller.enqueue(data);
controller.close();
}
});
const reader = stream.getReader();
console.log("开始读取文件内容:");
const lines = text.split('\n');
for (let i = 0; i < lines.length; i++) {
console.log(`第${i+1}行: ${lines[i]}`);
}
return lines;
}
export default async function handler(input) {
console.log("开始处理");
const path = input.path || "example.txt";
const pathInfo = await processPath(path);
const fileLines = await simulateFileReading();
return {
message: '处理完成',
pathInfo: pathInfo,
fileContent: fileLines,
linesCount: fileLines.length
};
}