Ejemplo n.º 1
0
        public static AbstractChunk From(Stream stream)
        {
            AbstractChunk chunk;
            Span <byte>   buffer = stackalloc byte[4];

            stream.Read(buffer);
            if (BitConverter.IsLittleEndian)
            {
                buffer.Reverse();
            }
            int length = (int)Unsafe.ReadUnaligned <uint>(ref MemoryMarshal.GetReference(buffer));

            stream.Read(buffer);
            string type = Encoding.ASCII.GetString(buffer);

            switch (type)
            {
            case "tEXt":
                chunk = new TextualChunk();
                break;

            default:
                chunk = new RawChunk();
                break;
            }
            chunk.Length = length;
            chunk.Type   = type;
            chunk.HandleChunkData(stream);
            stream.Read(buffer);
            if (BitConverter.IsLittleEndian)
            {
                buffer.Reverse();
            }
            chunk.Crc = Unsafe.ReadUnaligned <uint>(ref MemoryMarshal.GetReference(buffer));
            return(chunk);
        }
Ejemplo n.º 2
0
        public void AddTextualData(string keyword, string text)
        {
            TextualChunk textualChunk = new TextualChunk(keyword, text);

            Chunks.Insert(Chunks.Count - 2, textualChunk);
        }