public static AbstractTag ReadFromGzippedFile(String filename) { using (FileStream input = File.OpenRead(filename)) { using (GZipStream gzipStream = new GZipStream(input, CompressionMode.Decompress)) { return(AbstractTag.Read(gzipStream)); } } }
public static AbstractTag ReadFromFile(String filename) { AbstractTag tag = null; //Check if gzipped stream try { using (FileStream input = File.OpenRead(filename)) { using (GZipStream gzipStream = new GZipStream(input, CompressionMode.Decompress)) { tag = AbstractTag.Read(gzipStream); } } } catch (Exception) { tag = null; } if (tag != null) { return(tag); } //Try Deflate stream try { using (FileStream input = File.OpenRead(filename)) { using (DeflateStream deflateStream = new DeflateStream(input, CompressionMode.Decompress)) { tag = AbstractTag.Read(deflateStream); } } } catch (Exception) { tag = null; } if (tag != null) { return(tag); } //Assume uncompressed stream using (FileStream input = File.OpenRead(filename)) { tag = AbstractTag.Read(input); } return(tag); }
internal static Dictionary <String, AbstractTag> ReadDictionary(Stream input) { Dictionary <String, AbstractTag> dict = new Dictionary <String, AbstractTag>(); AbstractTag tag = AbstractTag.Read(input); while (tag.Type != TagType.End) { dict[tag.Name] = tag; tag = AbstractTag.Read(input); } return(dict); }
internal static List <AbstractTag> ReadTagList(Stream input) { TagType tagType = (TagType)TagByte.ReadByte(input); int length = TagInt.ReadInt(input); List <AbstractTag> tags = new List <AbstractTag>(); for (int i = 0; i < length; i++) { AbstractTag tag = null; switch (tagType) { case TagType.Byte: tag = TagByte.ReadUnnamedTagByte(input); break; case TagType.ByteArray: tag = TagByteArray.ReadUnnamedTagByteArray(input); break; case TagType.Compound: tag = TagCompound.ReadUnnamedTagCompound(input); break; case TagType.Double: tag = TagDouble.ReadUnnamedTagDouble(input); break; case TagType.End: tag = new TagEnd(); break; case TagType.Float: tag = TagFloat.ReadUnnamedTagFloat(input); break; case TagType.Int: tag = TagInt.ReadUnnamedTagInt(input); break; case TagType.IntArray: tag = TagIntArray.ReadUnnamedTagIntArray(input); break; case TagType.List: tag = TagList.ReadUnnamedTagList(input); break; case TagType.Long: tag = TagLong.ReadUnnamedTagLong(input); break; case TagType.Short: tag = TagShort.ReadUnnamedTagShort(input); break; case TagType.String: tag = TagString.ReadUnnamedTagString(input); break; default: tag = null; break; } if (tag != null) { tags.Add(tag); } } return(tags); }
public void SetTag(String name, AbstractTag tag) { tag.Name = name; _dictionary[name] = tag; }