Răsfoiți Sursa

Test worker large file support

Lutz Roeder 11 luni în urmă
părinte
comite
cdeb53fa97
1 a modificat fișierele cu 10 adăugiri și 7 ștergeri
  1. 10 7
      test/worker.js

+ 10 - 7
test/worker.js

@@ -1,5 +1,6 @@
 
 import * as base from '../source/base.js';
+import * as desktop from '../source/desktop.mjs';
 import * as fs from 'fs/promises';
 import * as path from 'path';
 import * as process from 'process';
@@ -97,11 +98,14 @@ host.TestHost = class {
         if (!exists) {
             throw new Error(`The file '${file}' does not exist.`);
         }
+        const stats = await fs.stat(pathname);
+        if (stats.isDirectory()) {
+            throw new Error(`The path '${file}' is a directory.`);
+        }
         if (encoding) {
             return await fs.readFile(pathname, encoding);
         }
-        const buffer = await fs.readFile(pathname, null);
-        return new base.BinaryStream(buffer);
+        return new desktop.FileStream(pathname, 0, stats.size, stats.mtimeMs);
     }
 
     event(/* name, params */) {
@@ -545,15 +549,14 @@ export class Target {
         const stat = await fs.stat(target);
         let context = null;
         if (stat.isFile()) {
-            const buffer = await fs.readFile(target, null);
-            const reader = new base.BinaryStream(buffer);
+            const stream = new desktop.FileStream(target, 0, stat.size, stat.mtimeMs);
             const dirname = path.dirname(target);
-            context = new host.TestHost.Context(this.host, dirname, identifier, reader, new Map());
+            context = new host.TestHost.Context(this.host, dirname, identifier, stream, new Map());
         } else if (stat.isDirectory()) {
             const entries = new Map();
             const file = async (pathname) => {
-                const buffer = await fs.readFile(pathname, null);
-                const stream = new base.BinaryStream(buffer);
+                const stat = await fs.stat(pathname);
+                const stream = new desktop.FileStream(pathname, 0, stat.size, stat.mtimeMs);
                 const name = pathname.split(path.sep).join(path.posix.sep);
                 entries.set(name, stream);
             };