@@ -1621,7 +1621,6 @@ typedef struct fioGZFile
16211621 z_stream strm ;
16221622 int fd ;
16231623 int errnum ;
1624- bool compress ;
16251624 bool eof ;
16261625 Bytef buf [ZLIB_BUFFER_SIZE ];
16271626} fioGZFile ;
@@ -1657,48 +1656,30 @@ gzFile
16571656fio_gzopen (fio_location location , const char * path , const char * mode , int level )
16581657{
16591658 int rc ;
1659+
1660+ if (strchr (mode , 'w' ) != NULL ) /* compress */
1661+ {
1662+ Assert (false);
1663+ elog (ERROR , "fio_gzopen(\"wb\") is not implemented" );
1664+ }
1665+
16601666 if (fio_is_remote (location ))
16611667 {
16621668 fioGZFile * gz = (fioGZFile * ) pgut_malloc (sizeof (fioGZFile ));
16631669 memset (& gz -> strm , 0 , sizeof (gz -> strm ));
16641670 gz -> eof = 0 ;
16651671 gz -> errnum = Z_OK ;
1666- /* check if file opened for writing */
1667- if (strcmp (mode , PG_BINARY_W ) == 0 ) /* compress */
1672+ gz -> strm .next_in = gz -> buf ;
1673+ gz -> strm .avail_in = ZLIB_BUFFER_SIZE ;
1674+ rc = inflateInit2 (& gz -> strm , 15 + 16 );
1675+ gz -> strm .avail_in = 0 ;
1676+ if (rc == Z_OK )
16681677 {
1669- gz -> strm .next_out = gz -> buf ;
1670- gz -> strm .avail_out = ZLIB_BUFFER_SIZE ;
1671- rc = deflateInit2 (& gz -> strm ,
1672- level ,
1673- Z_DEFLATED ,
1674- MAX_WBITS + 16 , DEF_MEM_LEVEL ,
1675- Z_DEFAULT_STRATEGY );
1676- if (rc == Z_OK )
1678+ gz -> fd = fio_open (location , path , O_RDONLY | PG_BINARY );
1679+ if (gz -> fd < 0 )
16771680 {
1678- gz -> compress = 1 ;
1679- gz -> fd = fio_open (location , path , O_WRONLY | O_CREAT | O_EXCL | PG_BINARY );
1680- if (gz -> fd < 0 )
1681- {
1682- free (gz );
1683- return NULL ;
1684- }
1685- }
1686- }
1687- else
1688- {
1689- gz -> strm .next_in = gz -> buf ;
1690- gz -> strm .avail_in = ZLIB_BUFFER_SIZE ;
1691- rc = inflateInit2 (& gz -> strm , 15 + 16 );
1692- gz -> strm .avail_in = 0 ;
1693- if (rc == Z_OK )
1694- {
1695- gz -> compress = 0 ;
1696- gz -> fd = fio_open (location , path , O_RDONLY | PG_BINARY );
1697- if (gz -> fd < 0 )
1698- {
1699- free (gz );
1700- return NULL ;
1701- }
1681+ free (gz );
1682+ return NULL ;
17021683 }
17031684 }
17041685 if (rc != Z_OK )
@@ -1711,16 +1692,7 @@ fio_gzopen(fio_location location, const char* path, const char* mode, int level)
17111692 else
17121693 {
17131694 gzFile file ;
1714- /* check if file opened for writing */
1715- if (strcmp (mode , PG_BINARY_W ) == 0 )
1716- {
1717- int fd = open (path , O_WRONLY | O_CREAT | O_EXCL | PG_BINARY , FILE_PERMISSION );
1718- if (fd < 0 )
1719- return NULL ;
1720- file = gzdopen (fd , mode );
1721- }
1722- else
1723- file = gzopen (path , mode );
1695+ file = gzopen (path , mode );
17241696 if (file != NULL && level != Z_DEFAULT_COMPRESSION )
17251697 {
17261698 if (gzsetparams (file , level , Z_DEFAULT_STRATEGY ) != Z_OK )
@@ -1796,77 +1768,14 @@ fio_gzread(gzFile f, void *buf, unsigned size)
17961768 }
17971769}
17981770
1799- int
1800- fio_gzwrite (gzFile f , void const * buf , unsigned size )
1801- {
1802- if ((size_t )f & FIO_GZ_REMOTE_MARKER )
1803- {
1804- int rc ;
1805- fioGZFile * gz = (fioGZFile * )((size_t )f - FIO_GZ_REMOTE_MARKER );
1806-
1807- gz -> strm .next_in = (Bytef * )buf ;
1808- gz -> strm .avail_in = size ;
1809-
1810- do
1811- {
1812- if (gz -> strm .avail_out == ZLIB_BUFFER_SIZE ) /* Compress buffer is empty */
1813- {
1814- gz -> strm .next_out = gz -> buf ; /* Reset pointer to the beginning of buffer */
1815-
1816- if (gz -> strm .avail_in != 0 ) /* Has something in input buffer */
1817- {
1818- rc = deflate (& gz -> strm , Z_NO_FLUSH );
1819- Assert (rc == Z_OK );
1820- gz -> strm .next_out = gz -> buf ; /* Reset pointer to the beginning of buffer */
1821- }
1822- else
1823- {
1824- break ;
1825- }
1826- }
1827- rc = fio_write_async (gz -> fd , gz -> strm .next_out , ZLIB_BUFFER_SIZE - gz -> strm .avail_out );
1828- if (rc >= 0 )
1829- {
1830- gz -> strm .next_out += rc ;
1831- gz -> strm .avail_out += rc ;
1832- }
1833- else
1834- {
1835- return rc ;
1836- }
1837- } while (gz -> strm .avail_out != ZLIB_BUFFER_SIZE || gz -> strm .avail_in != 0 );
1838-
1839- return size ;
1840- }
1841- else
1842- {
1843- return gzwrite (f , buf , size );
1844- }
1845- }
1846-
18471771int
18481772fio_gzclose (gzFile f )
18491773{
18501774 if ((size_t )f & FIO_GZ_REMOTE_MARKER )
18511775 {
18521776 fioGZFile * gz = (fioGZFile * )((size_t )f - FIO_GZ_REMOTE_MARKER );
18531777 int rc ;
1854- if (gz -> compress )
1855- {
1856- gz -> strm .next_out = gz -> buf ;
1857- rc = deflate (& gz -> strm , Z_FINISH );
1858- Assert (rc == Z_STREAM_END && gz -> strm .avail_out != ZLIB_BUFFER_SIZE );
1859- deflateEnd (& gz -> strm );
1860- rc = fio_write (gz -> fd , gz -> buf , ZLIB_BUFFER_SIZE - gz -> strm .avail_out );
1861- if (rc != ZLIB_BUFFER_SIZE - gz -> strm .avail_out )
1862- {
1863- return -1 ;
1864- }
1865- }
1866- else
1867- {
1868- inflateEnd (& gz -> strm );
1869- }
1778+ inflateEnd (& gz -> strm );
18701779 rc = fio_close (gz -> fd );
18711780 free (gz );
18721781 return rc ;
@@ -1877,20 +1786,6 @@ fio_gzclose(gzFile f)
18771786 }
18781787}
18791788
1880- int
1881- fio_gzeof (gzFile f )
1882- {
1883- if ((size_t )f & FIO_GZ_REMOTE_MARKER )
1884- {
1885- fioGZFile * gz = (fioGZFile * )((size_t )f - FIO_GZ_REMOTE_MARKER );
1886- return gz -> eof ;
1887- }
1888- else
1889- {
1890- return gzeof (f );
1891- }
1892- }
1893-
18941789const char *
18951790fio_gzerror (gzFile f , int * errnum )
18961791{
0 commit comments