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