1 /* 2 * Copyright 2018-2023, Andrew Lindesay <apl@lindesay.co.nz>. 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 #ifndef DATA_IO_UTILS_H 6 #define DATA_IO_UTILS_H 7 8 9 #include <DataIO.h> 10 11 12 class DataIOUtils { 13 public: 14 static status_t CopyAll(BDataIO* target, BDataIO* source); 15 }; 16 17 18 /*! This is a data source (read only) that is restricted to a certain size. An 19 example of where this is used is with reading out the data from a tar 20 stream. The tar logic knows how long the data is and so is able to provide 21 a client this constrained view of the data that is only able to read a 22 constrained quantity of data from the delegate data source. This prevents 23 overflow reads from the tar file. 24 */ 25 26 class ConstraintedDataIO : public BDataIO { 27 public: 28 ConstraintedDataIO(BDataIO* delegate, 29 size_t limit); 30 virtual ~ConstraintedDataIO(); 31 32 virtual ssize_t Read(void* buffer, size_t size); 33 virtual ssize_t Write(const void* buffer, size_t size); 34 35 virtual status_t Flush(); 36 37 private: 38 BDataIO* fDelegate; 39 size_t fLimit; 40 }; 41 42 43 class Base64DecodingDataIO : public BDataIO { 44 public: 45 Base64DecodingDataIO(BDataIO* delegate, 46 char char62 = '+', char char63 = '/'); 47 virtual ~Base64DecodingDataIO(); 48 49 virtual ssize_t Read(void* buffer, size_t size); 50 virtual ssize_t Write(const void* buffer, size_t size); 51 52 virtual status_t Flush(); 53 54 private: 55 status_t _ReadSingleByte(void* buffer); 56 status_t _CharToInt(uint8 ch, uint8* value); 57 58 private: 59 BDataIO* fDelegate; 60 char fChar62; 61 char fChar63; 62 63 uint8 fNextByteAssembly; 64 uint8 fNextByteAssemblyBits; 65 }; 66 67 68 #endif // DATA_IO_UTILS_H 69