diff --git a/src/Filo/Core/FiloWriter.cs b/src/Filo/Core/FiloWriter.cs index bb63c35..58b7b6d 100644 --- a/src/Filo/Core/FiloWriter.cs +++ b/src/Filo/Core/FiloWriter.cs @@ -1,4 +1,5 @@ -using ManuHub.Filo.Utils; +using ManuHub.Filo.Shared; +using ManuHub.Filo.Utils; using System.Security.Cryptography; using System.Text; using System.Text.Json; @@ -145,7 +146,7 @@ public async Task WriteAsync() while ((read = await fs.ReadAsync(buffer)) > 0) { - var offset = output.Position; + var chunkStartOffset = output.Position; byte[] chunk = buffer[..read]; string hash = Convert.ToHexString(SHA256.HashData(chunk)); @@ -162,8 +163,8 @@ public async Task WriteAsync() entry.Chunks.Add(new FiloChunkIndex { Id = chunkId++, - Offset = offset, - Length = encrypted.Length, + Offset = chunkStartOffset, + Length = FiloConstants.IvSize + FiloConstants.LengthSize + encrypted.Length, Hash = hash }); } @@ -175,8 +176,8 @@ public async Task WriteAsync() entry.Chunks.Add(new FiloChunkIndex { Id = chunkId++, - Offset = offset, - Length = read, + Offset = chunkStartOffset, + Length = FiloConstants.LengthSize + read, Hash = hash }); } diff --git a/src/Filo/Shared/FiloConstants.cs b/src/Filo/Shared/FiloConstants.cs new file mode 100644 index 0000000..09ae3e6 --- /dev/null +++ b/src/Filo/Shared/FiloConstants.cs @@ -0,0 +1,9 @@ +namespace ManuHub.Filo.Shared; + +public static class FiloConstants +{ + public const string FooterMagic = "FLOF"; + + public const int IvSize = 16; + public const int LengthSize = 4; +} \ No newline at end of file