public async Task WriteFile(ImageFileDef image, string inFile) { if (!File.Exists(inFile)) { throw new Exception($"{inFile} does not exist"); } var inBytes = File.ReadAllBytes(inFile); if (inBytes.Length > image.Length) { throw new Exception($"{Path.GetFileName(inFile)} is larger than original image"); } byte[] bytes = new byte[image.Length]; for (var i = 0; i < inBytes.Length; ++i) { bytes[i] = inBytes[i]; } using (var writer = File.OpenWrite(_outFile)) { writer.Seek(image.Start, SeekOrigin.Begin); await writer.WriteAsync(bytes, 0, bytes.Length); } }
private async Task ReadFile(ImageFileDef image) { var outf = $"{_outDir}\\{image.FileName}.png"; byte[] test = new byte[image.Length]; using (var stream = File.OpenRead(_inFile)) { stream.Seek(image.Start, SeekOrigin.Begin); await stream.ReadAsync(test, 0, (int)image.Length); } using (FileStream stream = File.Open(outf, FileMode.Create)) { await stream.WriteAsync(test, 0, test.Length); } }