| 722 | } |
| 723 | |
| 724 | bool open(stream *f, const char *mode, bool needclose, int level) |
| 725 | { |
| 726 | if(file) return false; |
| 727 | for(; *mode; mode++) |
| 728 | { |
| 729 | if(*mode=='r') { reading = true; break; } |
| 730 | else if(*mode=='w') { writing = true; break; } |
| 731 | } |
| 732 | if(reading) |
| 733 | { |
| 734 | if(inflateInit2(&zfile, -MAX_WBITS) != Z_OK) reading = false; |
| 735 | } |
| 736 | else if(writing && deflateInit2(&zfile, level, Z_DEFLATED, -MAX_WBITS, min(MAX_MEM_LEVEL, 8), Z_DEFAULT_STRATEGY) != Z_OK) writing = false; |
| 737 | if(!reading && !writing) return false; |
| 738 | |
| 739 | autoclose = needclose; |
| 740 | file = f; |
| 741 | crc = crc32(0, NULL, 0); |
| 742 | buf = new uchar[BUFSIZE]; |
| 743 | |
| 744 | if(reading) |
| 745 | { |
| 746 | if(!checkheader()) { stopreading(); file = NULL; return false; } |
| 747 | } |
| 748 | else if(writing) writeheader(); |
| 749 | return true; |
| 750 | } |
| 751 | |
| 752 | uint getcrc() { return crc; } |
| 753 |
no test coverage detected