| 88 | } |
| 89 | |
| 90 | static SRes Encode(ISeqOutStream *outStream, ISeqInStream *inStream, UInt64 fileSize) |
| 91 | { |
| 92 | SRes res; |
| 93 | size_t inSize = (size_t)fileSize; |
| 94 | Byte *inBuffer = 0; |
| 95 | Byte *outBuffer = 0; |
| 96 | Byte *filteredStream = 0; |
| 97 | size_t outSize; |
| 98 | CLzmaEncProps props; |
| 99 | |
| 100 | LzmaEncProps_Init(&props); |
| 101 | LzmaEncProps_Normalize(&props); |
| 102 | |
| 103 | if (inSize != 0) { |
| 104 | inBuffer = (Byte *)MyAlloc(inSize); |
| 105 | if (inBuffer == 0) |
| 106 | return SZ_ERROR_MEM; |
| 107 | } else { |
| 108 | return SZ_ERROR_INPUT_EOF; |
| 109 | } |
| 110 | |
| 111 | if (SeqInStream_Read(inStream, inBuffer, inSize) != SZ_OK) { |
| 112 | res = SZ_ERROR_READ; |
| 113 | goto Done; |
| 114 | } |
| 115 | |
| 116 | // we allocate 105% of original size + 64KB for output buffer |
| 117 | outSize = (size_t)fileSize / 20 * 21 + (1 << 16); |
| 118 | outBuffer = (Byte *)MyAlloc(outSize); |
| 119 | if (outBuffer == 0) { |
| 120 | res = SZ_ERROR_MEM; |
| 121 | goto Done; |
| 122 | } |
| 123 | |
| 124 | { |
| 125 | int i; |
| 126 | for (i = 0; i < 8; i++) |
| 127 | outBuffer[i + LZMA_PROPS_SIZE] = (Byte)(fileSize >> (8 * i)); |
| 128 | } |
| 129 | |
| 130 | if (mConType != NoConverter) |
| 131 | { |
| 132 | filteredStream = (Byte *)MyAlloc(inSize); |
| 133 | if (filteredStream == 0) { |
| 134 | res = SZ_ERROR_MEM; |
| 135 | goto Done; |
| 136 | } |
| 137 | memcpy(filteredStream, inBuffer, inSize); |
| 138 | |
| 139 | if (mConType == X86Converter) { |
| 140 | { |
| 141 | UInt32 x86State; |
| 142 | x86_Convert_Init(x86State); |
| 143 | x86_Convert(filteredStream, (SizeT) inSize, 0, &x86State, 1); |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 |
no test coverage detected