Skip to content

Commit 03d3f1f

Browse files
authored
Fix bundle loading (#1132)
Fix bundle loading by reading the bundle as raw data instead of UTF8 data before CRC32ing it Using .read() results in a CRC difference compared to the client
2 parents 96eda50 + 9b18b92 commit 03d3f1f

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

project/src/utils/FileSystem.ts

+10
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ export class FileSystem {
145145
return atomicallyRead(file, { encoding: "utf8" });
146146
}
147147

148+
/**
149+
* Reads a file as raw data and returns the contents as a Buffer.
150+
*
151+
* @param file The file path to read.
152+
* @returns A promise that resolves with the raw file contents as a Buffer.
153+
*/
154+
public readRaw(file: string): Promise<Buffer> {
155+
return atomicallyRead(file);
156+
}
157+
148158
/**
149159
* Writes data to a file, overwriting if the file already exists. If the parent directory does not exist, it's
150160
* created. File must be a file path (a buffer or a file descriptor is not allowed).

project/src/utils/FileSystemSync.ts

+10
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ export class FileSystemSync {
143143
return atomicallyReadSync(file, { encoding: "utf8" });
144144
}
145145

146+
/**
147+
* Reads a file as raw data and returns the contents as a Buffer.
148+
*
149+
* @param file The file path to read.
150+
* @returns The raw file contents as a Buffer.
151+
*/
152+
public readRaw(file: string): Buffer {
153+
return atomicallyReadSync(file);
154+
}
155+
146156
/**
147157
* Writes data to a file, overwriting if the file already exists. If the parent directory does not exist, it's
148158
* created. File must be a file path (a buffer or a file descriptor is not allowed).

project/src/utils/HashUtil.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class HashUtil {
3838
}
3939

4040
public generateCRC32ForFile(filePath: string): number {
41-
return crc32(this.fileSystemSync.read(filePath));
41+
return crc32(this.fileSystemSync.readRaw(filePath));
4242
}
4343
/**
4444
* Create a hash for the data parameter

0 commit comments

Comments
 (0)