public Chunker(Stream stream, HasherType type, uint significantHashBits) { //significantBitsMask = (uint)Math.Pow(2, significantHashBits); for (var i = 0; i < significantHashBits; i++) { significantBitsMask = (uint)((significantBitsMask << 1) + 1); } copyingStream = new CopyingStream(stream); this.hasher = AbstractRollingHasher.createInstance(type, copyingStream, WINDOW_SIZE); }
public StreamWriter OpenFileToWrite(string filename) { var stream = new CopyingStream(value => files[filename] = value); return(new StreamWriter(stream)); }
/// <summary> /// Reads a generic value from the stream /// </summary> /// <param name="tag">The tag number of the wrapping tags, or 255 for no wrapping tag</param> /// <returns>The read value</returns> public GenericValue ReadGeneric(byte tag = 255) { CopyingStream cstream = new CopyingStream(_stream); BinaryReader creader = new BinaryReader(cstream); Stream ostream = _stream; BinaryReader oreader = _reader; long end = 0; int depth = 0; ReadOpenTag(tag); if (_hasHeader) throw new Exception("Can't read generic tag when header is already cached"); try { _stream = cstream; _reader = creader; while (depth >= 0) { end = cstream.Position; _peekHeader(); // TODO: EOF handling if (_lvt == LVT.Type) { if (depth == 0 && _type == TagType.Close && _tagNumber == tag) break; else if (_type == TagType.Open) depth++; else if (_type == TagType.Close) depth--; } else if (_lvt == LVT.Length) { cstream.Skip(_length); } _hasHeader = false; } } finally { _stream = ostream; _reader = oreader; } ReadCloseTag(tag); return new TaggedGenericValue(cstream.MemoryStream.GetBuffer(), 0, (int)end); }
/// <summary> /// Reads a generic value from the stream /// </summary> /// <param name="tag">The tag number of the wrapping tags, or 255 for no wrapping tag</param> /// <returns>The read value</returns> public GenericValue ReadGeneric(byte tag = 255) { CopyingStream cstream = new CopyingStream(_stream); BinaryReader creader = new BinaryReader(cstream); Stream ostream = _stream; BinaryReader oreader = _reader; long end = 0; int depth = 0; ReadOpenTag(tag); if (_hasHeader) { throw new Exception("Can't read generic tag when header is already cached"); } try { _stream = cstream; _reader = creader; while (depth >= 0) { end = cstream.Position; _peekHeader(); // TODO: EOF handling if (_lvt == LVT.Type) { if (depth == 0 && _type == TagType.Close && _tagNumber == tag) { break; } else if (_type == TagType.Open) { depth++; } else if (_type == TagType.Close) { depth--; } } else if (_lvt == LVT.Length) { cstream.Skip(_length); } _hasHeader = false; } } finally { _stream = ostream; _reader = oreader; } ReadCloseTag(tag); return(new TaggedGenericValue(cstream.MemoryStream.GetBuffer(), 0, (int)end)); }