mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			24 lines
		
	
	
		
			675 B
		
	
	
	
		
			Swift
		
	
		
		
			
		
	
	
			24 lines
		
	
	
		
			675 B
		
	
	
	
		
			Swift
		
	
| 
								 
											5 years ago
										 
									 | 
							
								import Foundation
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								internal extension Data {
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    init(from inputStream: InputStream) throws {
							 | 
						||
| 
								 | 
							
								        self.init()
							 | 
						||
| 
								 | 
							
								        inputStream.open()
							 | 
						||
| 
								 | 
							
								        defer { inputStream.close() }
							 | 
						||
| 
								 | 
							
								        let bufferSize = 1024
							 | 
						||
| 
								 | 
							
								        let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: bufferSize)
							 | 
						||
| 
								 | 
							
								        defer { buffer.deallocate() }
							 | 
						||
| 
								 | 
							
								        while inputStream.hasBytesAvailable {
							 | 
						||
| 
								 | 
							
								            let count = inputStream.read(buffer, maxLength: bufferSize)
							 | 
						||
| 
								 | 
							
								            if count < 0 {
							 | 
						||
| 
								 | 
							
								                throw inputStream.streamError!
							 | 
						||
| 
								 | 
							
								            } else if count == 0 {
							 | 
						||
| 
								 | 
							
								                break
							 | 
						||
| 
								 | 
							
								            } else {
							 | 
						||
| 
								 | 
							
								                append(buffer, count: count)
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 |