From 54dfb40a05e2077f02568b310ebb65e7c8d09115 Mon Sep 17 00:00:00 2001 From: hyphen-o Date: Wed, 2 Oct 2024 18:52:53 +0900 Subject: [PATCH] =?UTF-8?q?.git/index=E3=83=91=E3=82=B9=E3=81=AE=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/models/git-index.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/models/git-index.ts b/src/models/git-index.ts index 777a5db..5cd5efb 100644 --- a/src/models/git-index.ts +++ b/src/models/git-index.ts @@ -24,6 +24,7 @@ interface Entry { export class GitIndex { private entries: Array; private readonly VERSION = 2; + private readonly SIGNATURE = 'DIRC' constructor(private readonly gitIndexPath: string) { this.entries = []; @@ -61,7 +62,7 @@ export class GitIndex { this.entries.push(entry); }; - public dumpIndex = async (): Promise => { + public dumpIndex = async (): Promise> => { const headerBuffer = this.createHeaderBuffer(); const entriesBuffer = this.createEntriesBuffer(); const checkSumBuffer = this.createCheckSumBuffer(entriesBuffer); @@ -72,7 +73,9 @@ export class GitIndex { Uint8Array.from(checkSumBuffer), ]); - await writeFile(GIT_INDEX, Uint8Array.from(indexBuffer)); + await writeFile(this.gitIndexPath, Uint8Array.from(indexBuffer)); + + return this.entries.map(entry => entry.filePath) }; private parseEntries = async (): Promise => { @@ -91,8 +94,8 @@ export class GitIndex { private createHeaderBuffer = (): Buffer => { const headerBuffer = Buffer.alloc(12); // https://www.w3schools.com/nodejs/met_buffer_write.asp - headerBuffer.write("DIRC", 0, 2); - headerBuffer.writeUInt32BE(2, 4); + headerBuffer.write(this.SIGNATURE, 0, 2); + headerBuffer.writeUInt32BE(this.VERSION, 4); headerBuffer.writeUInt32BE(this.entries.length, 8); return headerBuffer; };