@@ -1621,7 +1621,6 @@ typedef struct fioGZFile
1621
1621
z_stream strm ;
1622
1622
int fd ;
1623
1623
int errnum ;
1624
- bool compress ;
1625
1624
bool eof ;
1626
1625
Bytef buf [ZLIB_BUFFER_SIZE ];
1627
1626
} fioGZFile ;
@@ -1657,48 +1656,30 @@ gzFile
1657
1656
fio_gzopen (fio_location location , const char * path , const char * mode , int level )
1658
1657
{
1659
1658
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
+
1660
1666
if (fio_is_remote (location ))
1661
1667
{
1662
1668
fioGZFile * gz = (fioGZFile * ) pgut_malloc (sizeof (fioGZFile ));
1663
1669
memset (& gz -> strm , 0 , sizeof (gz -> strm ));
1664
1670
gz -> eof = 0 ;
1665
1671
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 )
1668
1677
{
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 )
1677
1680
{
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 ;
1702
1683
}
1703
1684
}
1704
1685
if (rc != Z_OK )
@@ -1711,16 +1692,7 @@ fio_gzopen(fio_location location, const char* path, const char* mode, int level)
1711
1692
else
1712
1693
{
1713
1694
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 );
1724
1696
if (file != NULL && level != Z_DEFAULT_COMPRESSION )
1725
1697
{
1726
1698
if (gzsetparams (file , level , Z_DEFAULT_STRATEGY ) != Z_OK )
@@ -1796,77 +1768,14 @@ fio_gzread(gzFile f, void *buf, unsigned size)
1796
1768
}
1797
1769
}
1798
1770
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
-
1847
1771
int
1848
1772
fio_gzclose (gzFile f )
1849
1773
{
1850
1774
if ((size_t )f & FIO_GZ_REMOTE_MARKER )
1851
1775
{
1852
1776
fioGZFile * gz = (fioGZFile * )((size_t )f - FIO_GZ_REMOTE_MARKER );
1853
1777
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 );
1870
1779
rc = fio_close (gz -> fd );
1871
1780
free (gz );
1872
1781
return rc ;
@@ -1877,20 +1786,6 @@ fio_gzclose(gzFile f)
1877
1786
}
1878
1787
}
1879
1788
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
-
1894
1789
const char *
1895
1790
fio_gzerror (gzFile f , int * errnum )
1896
1791
{
0 commit comments