mirror of
				https://github.com/davidgiven/fluxengine.git
				synced 2025-10-24 11:11:02 -07:00 
			
		
		
		
	Add a few more useful functions.
This commit is contained in:
		
							
								
								
									
										10
									
								
								lib/bytes.cc
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								lib/bytes.cc
									
									
									
									
									
								
							| @@ -273,6 +273,16 @@ ByteWriter Bytes::writer() | ||||
|     return ByteWriter(*this); | ||||
| } | ||||
|  | ||||
| ByteWriter& ByteWriter::operator +=(std::istream& stream) | ||||
| { | ||||
|     Bytes buffer(4096); | ||||
|  | ||||
|     while (stream.read((char*) buffer.begin(), buffer.size())) | ||||
|         this->append(buffer); | ||||
|     this->append(buffer.slice(0, stream.gcount())); | ||||
|     return *this; | ||||
| } | ||||
|  | ||||
| void BitWriter::push(uint32_t bits, size_t size) | ||||
| { | ||||
|     bits <<= 32-size; | ||||
|   | ||||
							
								
								
									
										15
									
								
								lib/bytes.h
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								lib/bytes.h
									
									
									
									
									
								
							| @@ -69,7 +69,7 @@ public: | ||||
|  | ||||
|     unsigned pos = 0; | ||||
|     bool eof() const | ||||
|     { return pos == _bytes.size(); } | ||||
|     { return pos >= _bytes.size(); } | ||||
|  | ||||
|     ByteReader& seek(unsigned pos) | ||||
|     { | ||||
| @@ -77,6 +77,12 @@ public: | ||||
|         return *this; | ||||
|     } | ||||
|  | ||||
|     ByteReader& skip(int delta) | ||||
|     { | ||||
|         this->pos += delta; | ||||
|         return *this; | ||||
|     } | ||||
|  | ||||
|     const Bytes read(unsigned len) | ||||
|     { | ||||
|         const Bytes bytes = _bytes.slice(pos, len); | ||||
| @@ -256,11 +262,18 @@ public: | ||||
|         return *this; | ||||
|     } | ||||
|  | ||||
|     ByteWriter& operator += (std::istream& stream); | ||||
|  | ||||
|     ByteWriter& append(const Bytes data) | ||||
|     { | ||||
|         return *this += data; | ||||
|     } | ||||
|  | ||||
|     ByteWriter& append(std::istream& stream) | ||||
|     { | ||||
|         return *this += stream; | ||||
|     } | ||||
|  | ||||
| private: | ||||
|     Bytes& _bytes; | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user