Added compression on saving, Daniel.

This commit is contained in:
Daniel Veillard 1998-09-23 00:49:46 +00:00
parent 70120ffb43
commit 151b1b0c2d
6 changed files with 85 additions and 8 deletions

View File

@ -1,3 +1,9 @@
Tue Sep 22 20:47:38 EDT 1998
* tree.c, tree.h: added saving with compression and added interfaces
to control the compression level (xmlGetCompressMode,
xmlSetCompressMode) and a new save to filename function (xmlSaveFile).
Mon Sep 21 20:11:13 EDT 1998 Daniel Veillard <Daniel.Veillard@w3.org>
* parser.c: corrected a loop for files of size 0

View File

@ -122,8 +122,8 @@ typedef struct xmlSAXHandler {
* Global variables: just the SAX interface tables we are looking for full
* reentrancy of the code !
*/
xmlSAXLocator xmlDefaultSAXLocator;
xmlSAXHandler xmlDefaultSAXHandler;
extern xmlSAXLocator xmlDefaultSAXLocator;
extern xmlSAXHandler xmlDefaultSAXHandler;
/*
* Interfaces

View File

@ -166,11 +166,15 @@ extern void xmlSetNs(xmlNodePtr node, xmlNsPtr ns);
extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
const CHAR *name, CHAR *content);
extern void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size);
extern void xmlDocDump(FILE *f, xmlDocPtr doc);
extern void xmlBufferWriteCHAR(const CHAR *string);
extern void xmlBufferWriteChar(const char *string);
extern void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size);
extern void xmlDocDump(FILE *f, xmlDocPtr doc);
int xmlSaveFile(const char *filename, xmlDocPtr cur);
extern int xmlGetCompressMode(void);
extern void xmlSetCompressMode(int mode);
#ifdef __cplusplus
}

View File

@ -122,8 +122,8 @@ typedef struct xmlSAXHandler {
* Global variables: just the SAX interface tables we are looking for full
* reentrancy of the code !
*/
xmlSAXLocator xmlDefaultSAXLocator;
xmlSAXHandler xmlDefaultSAXHandler;
extern xmlSAXLocator xmlDefaultSAXLocator;
extern xmlSAXHandler xmlDefaultSAXHandler;
/*
* Interfaces

63
tree.c
View File

@ -8,11 +8,16 @@
* TODO Cleanup the Dump mechanism.
*/
#include "config.h"
#include <stdio.h>
#include <ctype.h>
#include <malloc.h>
#include <string.h> /* for memset() only ! */
#ifdef HAVE_ZLIB_H
#include <zlib.h>
#endif
#include "tree.h"
#include "entities.h"
@ -1149,6 +1154,21 @@ void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size) {
*size = buffer_index;
}
/*
* Get the compression mode
*/
static int xmlCompressMode = 0;
int xmlGetCompressMode(void) {
return(xmlCompressMode);
}
void xmlSetCompressMode(int mode) {
if (mode < 0) xmlCompressMode = 0;
if (mode > 9) xmlCompressMode = 9;
else xmlCompressMode = mode;
}
/*
* Dump an XML document to the given FD
*/
@ -1164,6 +1184,49 @@ void xmlDocDump(FILE *f, xmlDocPtr cur) {
fwrite(buffer, sizeof(CHAR), buffer_index, f);
}
/*
* Dump an XML document to a file.
*/
int xmlSaveFile(const char *filename, xmlDocPtr cur) {
#ifdef HAVE_ZLIB_H
gzFile zoutput = NULL;
char mode[15];
#endif
FILE *output;
int ret;
#ifdef HAVE_ZLIB_H
if ((xmlCompressMode > 0) && (xmlCompressMode <= 9)) {
sprintf(mode, "w%d", xmlCompressMode);
zoutput = gzopen(filename, mode);
}
if (zoutput == NULL) {
#endif
output = fopen(filename, "w");
if (output == NULL) return(-1);
#ifdef HAVE_ZLIB_H
}
#endif
/*
* save the content to a temp buffer.
*/
buffer_index = 0;
xmlDocContentDump(cur);
#ifdef HAVE_ZLIB_H
if (zoutput != NULL) {
ret = gzwrite(zoutput, buffer, sizeof(CHAR) * buffer_index);
gzclose(zoutput);
return(ret);
}
#endif
ret = fwrite(buffer, sizeof(CHAR), buffer_index, output);
fclose(output);
return(ret * sizeof(CHAR));
}
/************************************************************************
* *
* Debug *

8
tree.h
View File

@ -166,11 +166,15 @@ extern void xmlSetNs(xmlNodePtr node, xmlNsPtr ns);
extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
const CHAR *name, CHAR *content);
extern void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size);
extern void xmlDocDump(FILE *f, xmlDocPtr doc);
extern void xmlBufferWriteCHAR(const CHAR *string);
extern void xmlBufferWriteChar(const char *string);
extern void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size);
extern void xmlDocDump(FILE *f, xmlDocPtr doc);
int xmlSaveFile(const char *filename, xmlDocPtr cur);
extern int xmlGetCompressMode(void);
extern void xmlSetCompressMode(int mode);
#ifdef __cplusplus
}