-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(compile): correct buffered reading of assets and files (#27008)
Closes #27006
- Loading branch information
Showing
14 changed files
with
104 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"tempDir": true, | ||
"steps": [{ | ||
"args": "run -A setup.js", | ||
"output": "[WILDCARD]" | ||
}, { | ||
"if": "unix", | ||
"args": "compile --allow-read=data --include data --output main main.ts", | ||
"output": "[WILDCARD]" | ||
}, { | ||
"if": "unix", | ||
"commandName": "./main", | ||
"args": [], | ||
"output": "[WILDCARD]", | ||
"exitCode": 0 | ||
}, { | ||
"if": "windows", | ||
"args": "compile --allow-read=data --include data --output main.exe main.ts", | ||
"output": "[WILDCARD]" | ||
}, { | ||
"if": "windows", | ||
"commandName": "./main.exe", | ||
"args": [], | ||
"output": "[WILDCARD]", | ||
"exitCode": 0 | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// buffer larger than file | ||
{ | ||
using file = Deno.openSync(import.meta.dirname + "/data/1.txt"); | ||
const data = new Uint8Array(13); | ||
const len = file.readSync(data); | ||
if (len !== 13) { | ||
throw new Error("Unexpected read length"); | ||
} | ||
if (file.readSync(new Uint8Array(1024)) !== null) { | ||
throw new Error("Unexpected."); | ||
} | ||
const textData = new TextDecoder().decode(data); | ||
if (textData !== "Hello, world!") { | ||
throw new Error("Unexpected file data (1): " + textData); | ||
} | ||
} | ||
|
||
// buffer smaller than file | ||
{ | ||
using file = Deno.openSync(import.meta.dirname + "/data/1.txt"); | ||
const finalData = new Uint8Array(13); | ||
const data = new Uint8Array(2); | ||
let pos = 0; | ||
while (true) { | ||
const len = file.readSync(data); | ||
if (len === 0 || len == null) { | ||
break; | ||
} | ||
finalData.set(data.subarray(0, len), pos); | ||
pos += len; | ||
} | ||
const textData = new TextDecoder().decode(finalData); | ||
if (textData !== "Hello, world!") { | ||
throw new Error("Unexpected file data (2): " + textData); | ||
} | ||
} | ||
|
||
// large amount of data, small reads | ||
{ | ||
const bytes = new Uint8Array((1024 ** 2) * 20); | ||
using file = Deno.openSync(import.meta.dirname + "/data/2.dat"); | ||
const buffer = new Uint8Array(2); | ||
let pos = 0; | ||
while (true) { | ||
const len = file.readSync(buffer); | ||
if (len === 0 || len == null) { | ||
break; | ||
} | ||
bytes.set(buffer.subarray(0, len), pos); | ||
pos += len; | ||
} | ||
for (let i = 0; i < bytes.length; i++) { | ||
if (bytes[i] !== i % 256) { | ||
throw new Error("Unexpected data."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Deno.mkdirSync("data"); | ||
Deno.writeTextFileSync("data/1.txt", "Hello, world!"); | ||
const bytes = new Uint8Array((1024 ** 2) * 20); | ||
for (let i = 0; i < bytes.length; i++) { | ||
bytes[i] = i % 256; | ||
} | ||
Deno.writeFileSync("data/2.dat", bytes); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.