Changeset 1527 for trunk/src/core/RpBuffer.cc
- Timestamp:
- Jun 22, 2009 12:38:49 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/RpBuffer.cc
r1384 r1527 120 120 if (f == NULL) { 121 121 status.addError("can't open \"%s\": %s", filePath, strerror(errno)); 122 122 return false; 123 123 } 124 124 struct stat stat; 125 125 if (fstat(fileno(f), &stat) < 0) { 126 126 status.addError("can't stat \"%s\": %s", filePath, strerror(errno)); 127 128 } 127 return false; 128 } 129 129 off_t size; 130 130 size = stat.st_size; … … 133 133 if (memblock == NULL) { 134 134 status.addError("can't allocate %d bytes for file \"%s\": %s", 135 135 size, filePath, strerror(errno)); 136 136 fclose(f); 137 137 return false; … … 139 139 140 140 // FIXME: better yet, create an "extend" method in the buffer and returns 141 // 142 // 141 // the address of the char buffer so I can read the data directly 142 // into the buffer. This eliminates memory new/copy/delete ops. 143 143 144 144 size_t nRead; 145 145 nRead = fread(memblock, sizeof(char), size, f); 146 fclose(f); 146 fclose(f); // Close the file. 147 147 148 148 if (nRead != (size_t)size) { 149 149 status.addError("can't read %d bytes from \"%s\": %s", size, filePath, 150 151 return false; 152 } 150 strerror(errno)); 151 return false; 152 } 153 153 154 154 int nBytes; … … 158 158 if (nBytes != size) { 159 159 status.addError("can't append %d bytes from \"%s\" to buffer: %s", 160 161 return false; 162 } 160 size, filePath, strerror(errno)); 161 return false; 162 } 163 163 return true; 164 164 } … … 174 174 if (f != NULL) { 175 175 status.addError("can't open \"%s\": %s\n", filePath, strerror(errno)); 176 176 return false; 177 177 } 178 178 ssize_t nWritten; 179 179 nWritten = fwrite(bytes(), size(), sizeof(char), f); 180 fclose(f); 181 180 fclose(f); // Close the file. 181 182 182 if (nWritten != (ssize_t)size()) { 183 183 status.addError("can't write %d bytes to \"%s\": %s\n", size(), 184 185 184 filePath, strerror(errno)); 185 return false; 186 186 } 187 187 return true; … … 198 198 switch (flags & (RPENC_Z | RPENC_B64)) { 199 199 case 0: 200 201 202 case RPENC_Z: 203 204 205 206 207 208 209 case RPENC_B64: 200 break; 201 202 case RPENC_Z: // Compress only 203 if (!do_compress(status, *this, bout)) { 204 return false; 205 } 206 move(bout); 207 break; 208 209 case RPENC_B64: // Encode only 210 210 if (!do_base64_enc(status, *this, bout)) { 211 211 return false; 212 212 } 213 214 213 move(bout); 214 break; 215 215 216 216 case (RPENC_B64 | RPENC_Z): 217 218 219 220 221 217 218 // It's always compress then encode 219 if (!do_compress(status, *this, bout)) { 220 return false; 221 } 222 222 if (!do_base64_enc(status, bout, *this)) { 223 223 return false; 224 224 } 225 225 break; 226 226 } 227 227 return true; … … 238 238 switch (flags & (RPENC_Z | RPENC_B64)) { 239 239 case 0: 240 241 242 243 244 245 246 247 248 249 250 251 252 253 break; 254 255 case RPENC_Z: 256 257 258 259 260 261 262 case RPENC_B64: 240 if (encoding::isBase64(bytes(), size())) { 241 if (!do_base64_dec(status, *this, bout)) { 242 return false; 243 } 244 move(bout); 245 } 246 bout.clear(); 247 if (encoding::isBinary(bytes(), size())) { 248 if (!do_decompress(status, *this, bout)) { 249 return false; 250 } 251 move(bout); 252 } 253 break; 254 255 case RPENC_Z: // Decompress only 256 if (!do_decompress(status, *this, bout)) { 257 return false; 258 } 259 move(bout); 260 break; 261 262 case RPENC_B64: // Decode only 263 263 if (!do_base64_dec(status, *this, bout)) { 264 264 return false; 265 265 } 266 267 266 move(bout); 267 break; 268 268 269 269 case (RPENC_B64 | RPENC_Z): 270 271 270 271 // It's always decode then decompress 272 272 if (!do_base64_dec(status, *this, bout)) { 273 273 return false; 274 274 } 275 276 277 278 279 275 clear(); 276 if (!do_decompress(status, bout, *this)) { 277 return false; 278 } 279 break; 280 280 } 281 281 return true; … … 285 285 bool 286 286 Buffer::do_compress(Outcome& status, SimpleCharBuffer& bin, 287 287 SimpleCharBuffer& bout) 288 288 { 289 289 int ret=0, flush=0; … … 357 357 bool 358 358 Buffer::do_decompress(Outcome& status, SimpleCharBuffer& bin, 359 359 SimpleCharBuffer& bout) 360 360 { 361 361 int ret; … … 433 433 bool 434 434 Buffer::do_base64_enc(Outcome& status, const SimpleCharBuffer& bin, 435 435 SimpleCharBuffer& bout ) 436 436 { 437 437 int tBufSize = 0; … … 453 453 bool 454 454 Buffer::do_base64_dec(Outcome& status, const SimpleCharBuffer& bin, 455 455 SimpleCharBuffer& bout ) 456 456 { 457 457 int tBufSize = 0;
Note: See TracChangeset
for help on using the changeset viewer.