Skip to content

Commit 5879d22

Browse files
committed
Fix text files being treated as binaries if their size is big
1 parent bbe05f7 commit 5879d22

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/sync-manager.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,19 @@ export default class SyncManager {
723723
Object.keys(treeFiles)
724724
.filter((filePath: string) => treeFiles[filePath].content)
725725
.map(async (filePath: string) => {
726+
// Some Markdown or JSON files might grow to be quite big, that makes it
727+
// impossible for the file-type library to guess their file type.
728+
// It also increases the amount of memory used by A LOT and might cause
729+
// issues in devices with low memory if there are lots of files to check.
730+
//
731+
// I don't fully trust file extensions as they're not completely reliable
732+
// to determine the file type, though I feel it's ok to compromise and rely
733+
// on them if it makes the plugin handle upload better on certain devices.
734+
if (filePath.endsWith(".md") || filePath.endsWith(".json")) {
735+
this.metadataStore.data.files[filePath].sha =
736+
await this.calculateSHA(filePath);
737+
return;
738+
}
726739
const buffer = await this.vault.adapter.readBinary(filePath);
727740
const fileType = await fileTypeFromBuffer(buffer);
728741
let newSha = "";

0 commit comments

Comments
 (0)