public Buf Build() { int z; Buf b; this.fileList.Sort(); z = 0; z += HamCore.HamcoreHeaderSize; z += sizeof(int); foreach (HamCoreBuilderFileEntry f in this.fileList) { z += Str.ShiftJisEncoding.GetByteCount(f.Name) + sizeof(int); z += sizeof(int); z += sizeof(int); z += sizeof(int); } foreach (HamCoreBuilderFileEntry f in this.fileList) { f.Offset = z; z += (int)f.CompressedData.Size; } b = new Buf(); b.Write(Str.ShiftJisEncoding.GetBytes(HamCore.HamcoreHeaderData)); b.WriteInt((uint)this.fileList.Count); foreach (HamCoreBuilderFileEntry f in this.fileList) { b.WriteStr(f.Name, true); b.WriteInt(f.RawData.Size); b.WriteInt(f.CompressedData.Size); b.WriteInt((uint)f.Offset); } foreach (HamCoreBuilderFileEntry f in this.fileList) { b.Write(f.CompressedData.ByteData); } b.SeekToBegin(); return(b); }
public Buf ToBuf() { string s = ToString(); Buf b = new Buf(); byte[] bom = Str.GetBOM(this.Encoding); if (bom != null) { b.Write(bom); } b.Write(encoding.GetBytes(s)); b.SeekToBegin(); return(b); }
public static Buf ReadFromStream(Stream st) { Buf ret = new Buf(); int size = 32767; while (true) { byte[] tmp = new byte[size]; int i = st.Read(tmp, 0, tmp.Length); if (i <= 0) { break; } Array.Resize <byte>(ref tmp, i); ret.Write(tmp); } ret.SeekToBegin(); return(ret); }
public static Buf ReadFromStream(Stream st) { Buf ret = new Buf(); int size = 32767; while (true) { byte[] tmp = new byte[size]; int i = st.Read(tmp, 0, tmp.Length); if (i <= 0) { break; } Array.Resize<byte>(ref tmp, i); ret.Write(tmp); } ret.SeekToBegin(); return ret; }
public Buf ReadHamcore(string name) { if (name[0] == '|') { name = name.Substring(1); } if (name[0] == '/' || name[0] == '\\') { name = name.Substring(1); } string filename = name; filename = filename.Replace("/", "\\"); Buf b; if (this.disableReadRawFile == false) { try { b = Buf.ReadFromFile(HamcoreDirName + "\\" + filename); return(b); } catch { } } lock (list) { HamCoreEntry c; string key = filename.ToUpper(); b = null; if (list.ContainsKey(key)) { c = list[key]; if (c.Buffer != null) { b = new Buf(c.Buffer); b.SeekToBegin(); c.LastAccess = Time.Tick64; } else { if (hamcore_io.Seek(SeekOrigin.Begin, (int)c.Offset)) { byte[] data = hamcore_io.Read((int)c.SizeCompressed); int dstSize = (int)c.Size; byte[] buffer = ZLib.Uncompress(data, dstSize); c.Buffer = buffer; b = new Buf(buffer); b.SeekToBegin(); c.LastAccess = Time.Tick64; } } } long now = Time.Tick64; foreach (HamCoreEntry cc in list.Values) { if (cc.Buffer != null) { if (((cc.LastAccess + HamcoreCacheExpires) < now) || cc.FileName.StartsWith("Li", StringComparison.CurrentCultureIgnoreCase)) { cc.Buffer = null; } } } } return(b); }
public Buf ToBuf() { string s = ToString(); Buf b = new Buf(); byte[] bom = Str.GetBOM(this.Encoding); if (bom != null) { b.Write(bom); } b.Write(encoding.GetBytes(s)); b.SeekToBegin(); return b; }