Module description

zif -- gzip file reader
The zif module implements a gzip file reader. See gzf for the gzip file header information.

zif structure

zif% ( -- n )
Get the required space for a zif variable

gzip file reader variable creation, initialisation and destruction

zif-init ( zif -- )
Initialise the gzip file reader variable
zif-(free) ( zif -- )
Free the internal, private variables from the heap
zif-create ( "<spaces>name" -- ; -- zif )
Create a named gzip file reader variable in the dictionary
zif-new ( -- zif )
Create a new gzip file reader variable on the heap
zif-free ( zif -- )
Free the variable from the heap

Module words

zif+input-size! ( u -- )
Set the default input buffer size &lb;default 2kb, min. 1kb&rb;
zif+input-size@ ( -- u )
Get the default input buffer size
zif+output-size! ( u -- )
Set the default output buffer size &lb;default 64kb+4kb, min. 64kb+4kb&rb;
zif+output-size@ ( -- u )
Get the default output buffer size

Member words

zif-gzf@ ( zif -- gzf )
Get the reference to the gzip file header info after zif-read-header

File words

zif-open-file ( c-addr u zif -- ior )
Open an existing gzip file for reading with name c-addr u
zif-read-header ( zif -- ior )
Read the &lb;next&rb; header from the gzip file
zif-read-file ( c-addr1 u1 zif -- u2 ior )
Read/decompress maximum u1 bytes from the file and store those at c-addr1, return the actual read bytes
zif-close-file ( zif -- ior )
Close the file

Inspection

zif-dump ( zif -- )
Dump the variable

Examples

\ ==============================================================================
\
\          zif_expl - the gzip file reader example in the ffl
\
\               Copyright (C) 2009  Dick van Oudheusden
\  
\ This library is free software; you can redistribute it and/or
\ modify it under the terms of the GNU General Public
\ License as published by the Free Software Foundation; either
\ version 2 of the License, or (at your option) any later version.
\
\ This library is distributed in the hope that it will be useful,
\ but WITHOUT ANY WARRANTY; without even the implied warranty of
\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
\ General Public License for more details.
\
\ You should have received a copy of the GNU General Public
\ License along with this library; if not, write to the Free
\ Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
\
\ ==============================================================================
\ 
\  $Date: 2008-01-13 08:09:33 $ $Revision: 1.3 $
\
\ ==============================================================================

include ffl/zif.fs

\ Convert gzips modification time to a string

include ffl/dos.fs

dtm-create gzf-dtm
tos-create gzf-tos

: mtime-to-str ( u1 -- c-addr u2 = Convert gzips mtime u1 to the string c-addr u2 )
  0 dtm.unix-epoch gzf-dtm dtm-set-with-seconds  \ Calculate the date/time
  gzf-dtm s" %c" gzf-tos dos-write-format        \ Format the date/time string
  gzf-tos str-get                                \ Get the string
;


\ Copy contents gzip file to another file

: copy-to-file     ( c-addr u zif -- ior = Copy contents )
  >r
  r/w create-file throw           \ Create the destination file
  BEGIN                           \ Zolang data in gzip file Do
    pad 80 r@ zif-read-file
    dup 0= IF
      over 0>
    ELSE
      false
    THEN
  WHILE
    drop
    over pad -rot write-file throw  \  Write data in file
  REPEAT
  nip
  swap close-file throw
  rdrop
;


\ Example: Read a gzip file and save the result in a file

\ Create the gzip file reader variable

zif-new value zif1

s" gzipped.gz"  zif1 zif-open-file ?dup 0= [IF]
  .( gzipped.gz succesfully opened) cr

  \ Read the header info
  zif1 zif-read-header ?dup 0= [IF]
    
    \ Get the header info
    zif1 zif-gzf@
    .( Text file         : ) dup gzf-text@ . cr
    .( Operating system  : ) dup gzf-os@ . cr
    .( Modification time : ) dup gzf-mtime@ mtime-to-str type cr
    .( Name              : ) dup gzf-name@ type cr
    .( Comment           : ) dup gzf-comment@ type cr
    
    gzf-name@ zif1 copy-to-file ?dup 0= [IF]
      .( Gzip file is succesfully inflated.) cr
    [ELSE]
      .( Error during inflation: ) . cr
    [THEN]
  [THEN]
  
  zif1 zif-close-file drop
[ELSE]
  .( Error opening gzipped.gz:) . cr
[THEN]

\ Free the zif variable from the heap

zif1 zif-free


Generated by fsdocgen 0.1.0