| 118 | } |
| 119 | |
| 120 | int KmlRenderer::saveImage(imageObj *, FILE *fp, outputFormatObj *format) |
| 121 | { |
| 122 | /* -------------------------------------------------------------------- */ |
| 123 | /* Write out the document. */ |
| 124 | /* -------------------------------------------------------------------- */ |
| 125 | |
| 126 | int bufSize = 0; |
| 127 | xmlChar *buf = NULL; |
| 128 | msIOContext *context = NULL; |
| 129 | int chunkSize = 4096; |
| 130 | #if defined(CPL_ZIP_API_OFFERED) |
| 131 | int bZip = MS_FALSE; |
| 132 | #endif |
| 133 | |
| 134 | if( msIO_needBinaryStdout() == MS_FAILURE ) |
| 135 | return MS_FAILURE; |
| 136 | |
| 137 | xmlDocDumpFormatMemoryEnc(XmlDoc, &buf, &bufSize, "UTF-8", 1); |
| 138 | |
| 139 | #if defined(USE_OGR) |
| 140 | if (format && format->driver && strcasecmp(format->driver, "kmz") == 0) |
| 141 | { |
| 142 | #if defined(CPL_ZIP_API_OFFERED) |
| 143 | bZip = MS_TRUE; |
| 144 | #else |
| 145 | msSetError( MS_MISCERR, "kmz format support unavailable, perhaps you need to upgrade to GDAL/OGR 1.8?", |
| 146 | "KmlRenderer::saveImage()"); |
| 147 | xmlFree(buf); |
| 148 | return MS_FAILURE; |
| 149 | #endif |
| 150 | } |
| 151 | |
| 152 | #if defined(CPL_ZIP_API_OFFERED) |
| 153 | if (bZip) |
| 154 | { |
| 155 | VSILFILE *fpZip; |
| 156 | int bytes_read; |
| 157 | char buffer[1024]; |
| 158 | char *zip_filename =NULL; |
| 159 | void *hZip=NULL; |
| 160 | |
| 161 | zip_filename = msTmpFile(NULL, NULL, "/vsimem/kmlzip/", "kmz" ); |
| 162 | hZip = CPLCreateZip( zip_filename, NULL ); |
| 163 | CPLCreateFileInZip( hZip, "mapserver.kml", NULL ); |
| 164 | for (int i=0; i<bufSize; i+=chunkSize) |
| 165 | { |
| 166 | int size = chunkSize; |
| 167 | if (i + size > bufSize) |
| 168 | size = bufSize - i; |
| 169 | CPLWriteFileInZip( hZip, buf+i, size); |
| 170 | } |
| 171 | CPLCloseFileInZip( hZip ); |
| 172 | CPLCloseZip( hZip ); |
| 173 | |
| 174 | context = msIO_getHandler(fp); |
| 175 | fpZip = VSIFOpenL( zip_filename, "r" ); |
| 176 | |
| 177 | while( (bytes_read = VSIFReadL( buffer, 1, sizeof(buffer), fpZip )) > 0 ) |
no test coverage detected