private bool AnalyzeGifSignature(List <byte> gifData) { for (int i = 0; i < 6; i++) { GifSignature.Add(gifData[i]); } gifData.RemoveRange(0, 6); List <char> chars = GifSignature.ConvertAll(ByteToChar); string s = new string(chars.ToArray()); if (s == GifVersion.GIF89a.ToString()) { Version = GifVersion.GIF89a; } else if (s == GifVersion.GIF87a.ToString()) { Version = GifVersion.GIF87a; } else { return(false); } return(true); }
public bool Read(Stream stream) { byte[] headerData = new byte[6]; int readBytes = stream.Read(headerData, 0, 6); if (readBytes == 6) { string header = Encoding.ASCII.GetString(headerData); if (!header.StartsWith("GIF")) { return(false); } if (header.Substring(3, 3) == "89a") { Version = GifVersion.GIF89a; } else if (header.Substring(3, 3) == "87a") { Version = GifVersion.GIF87a; } else { return(false); } } else { return(false); } return(true); }
public async Task Writes_Correct_Version_Bytes(GifVersion version, byte[] expectedBytes) { var stream = new MemoryStream(); var writer = new GifWriter(stream); await writer.WriteVersionAsync(version); var writtenBytes = stream.ToArray(); CollectionAssert.AreEqual(expectedBytes, writtenBytes); }
public async Task WriteVersionAsync(GifVersion version) { byte[] toWrite; if (version == GifVersion.Gif87a) { toWrite = Encodings.Version87a; } else if (version == GifVersion.Gif89a) { toWrite = Encodings.Version89a; } else { throw new ArgumentException("Invalid version specified", nameof(version)); } await _outputStream.WriteAsync(toWrite, 0, toWrite.Length); }