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 *******************************************************************************/
17 #define BLOCKSIZE (128*1024)
20 int uncompressedCapacity;
23 int compressedCapacity;
27 void initWrite(FILE* _handle) {
28 uncompressedCapacity = BLOCKSIZE;
29 uncompressed = malloc(uncompressedCapacity);
31 compressedCapacity = 8 + BLOCKSIZE + (BLOCKSIZE/20);
32 compressed = malloc(compressedCapacity);
37 int uncompressedSize = position;
38 int compressedSize = fastlz_compress(uncompressed, uncompressedSize, compressed+8);
40 ((int*)compressed)[0] = compressedSize;
41 ((int*)compressed)[1] = uncompressedSize;
43 fwrite(compressed, compressedSize+8, 1, handle);
50 ((int*)compressed)[0] = 0;
51 ((int*)compressed)[1] = 0;
52 fwrite(compressed, 8, 1, handle);
61 void write(char* data, int offset, int length) {
64 while(length > uncompressedCapacity - position) {
65 s = uncompressedCapacity - position;
66 memcpy(uncompressed + position, data + offset, s);
72 memcpy(uncompressed + position, data + offset, length);