1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
18 int uncompressedCapacity;
\r
20 int uncompressedSize;
\r
22 int compressedCapacity;
\r
26 void initRead(FILE* _handle) {
\r
28 uncompressedCapacity = 0;
\r
30 uncompressedSize = 0;
\r
31 compressed = malloc(8);
\r
32 compressedCapacity = 8;
\r
47 fread(compressed, 8, 1, handle);
\r
48 compressedSize = ((int*)compressed)[0];
\r
49 uncompressedSize = ((int*)compressed)[1];
\r
51 if(compressedSize > compressedCapacity) {
\r
53 compressed = malloc(compressedSize);
\r
54 compressedCapacity = compressedSize;
\r
56 if(uncompressedSize > uncompressedCapacity) {
\r
58 uncompressed = malloc(uncompressedSize);
\r
59 uncompressedCapacity = uncompressedSize;
\r
62 fread(compressed, compressedSize, 1, handle);
\r
63 printf("decompress %d %d %d %d\n", compressedSize, compressedCapacity, uncompressedSize, uncompressedCapacity); fflush(stdout);
\r
64 fastlz_decompress(compressed, compressedSize, uncompressed, uncompressedSize);
\r
68 void read(char* data, int offset, int length) {
\r
71 while(length > uncompressedSize - position) {
\r
72 s = uncompressedSize - position;
\r
73 memcpy(data + offset, uncompressed + position, s);
\r
78 memcpy(data + offset, uncompressed + position, length);
\r