677 |
677 |
678 !ZipStream methodsFor:'startup & release'! |
678 !ZipStream methodsFor:'startup & release'! |
679 |
679 |
680 openWithMode:aMode on:aStream |
680 openWithMode:aMode on:aStream |
681 "open stream and write or check gzip header" |
681 "open stream and write or check gzip header" |
|
682 |
682 super openWithMode:aMode on:aStream. |
683 super openWithMode:aMode on:aStream. |
|
684 |
683 self isReadable ifTrue:[ |
685 self isReadable ifTrue:[ |
684 "Check for the gzip magic id" |
686 "Check for the gzip magic id" |
685 |flags| |
687 self readHeader |
686 |
|
687 GZ_MAGIC_ID do:[:b| |
|
688 onStream nextByte ~~ b ifTrue:[ self zerror:'version error' ] |
|
689 ]. |
|
690 |
|
691 onStream nextByte ~~ Z_DEFLATED ifTrue:[ |
|
692 self zerror:'invalid method (not deflated)' |
|
693 ]. |
|
694 |
|
695 flags := onStream nextByte. |
|
696 (flags bitAnd:HEAD_RESERVED) ~~ 0 ifTrue:[ |
|
697 self zerror:'wrong data format' |
|
698 ]. |
|
699 |
|
700 "discard time, xflags and OS code" |
|
701 onStream skip:6. |
|
702 |
|
703 (flags bitAnd:HEAD_EXTRA_FIELD) ~~ 0 ifTrue:[|len| |
|
704 "skip the extra field" |
|
705 len := onStream nextByte + (onStream nextByte bitShift:8). |
|
706 len timesRepeat:[ onStream nextByte ]. |
|
707 ]. |
|
708 |
|
709 (flags bitAnd:HEAD_ORIG_NAME) ~~ 0 ifTrue:[|b| |
|
710 "skip the original file name" |
|
711 [ (b := onStream nextByte) ~~ 0 ] whileTrue. |
|
712 ]. |
|
713 |
|
714 (flags bitAnd:HEAD_CRC) ~~ 0 ifTrue:[ |
|
715 "skip the header crc" |
|
716 onStream skip:2. |
|
717 ]. |
|
718 ] ifFalse:[ |
688 ] ifFalse:[ |
719 "write the gzip magic id |
689 "write the gzip magic id" |
720 " |
690 self writeHeader |
721 GZ_MAGIC_ID do:[:b| onStream nextPutByte:b ]. |
691 ]. |
722 |
692 ! |
723 "write the method" |
693 |
724 onStream nextPutByte:Z_DEFLATED. |
694 readHeader |
725 |
695 "Check for the gzip magic id" |
726 "write the flags" |
696 |flags| |
727 onStream nextPutByte:0. |
697 |
728 |
698 GZ_MAGIC_ID do:[:b| |
729 "write time" |
699 onStream nextByte ~~ b ifTrue:[ self zerror:'version error' ] |
730 4 timesRepeat:[ onStream nextPutByte:0 ]. |
700 ]. |
731 |
701 |
732 "write xflags" |
702 onStream nextByte ~~ Z_DEFLATED ifTrue:[ |
733 onStream nextPutByte:0. |
703 self zerror:'invalid method (not deflated)' |
734 |
704 ]. |
735 "write OS code" |
705 |
736 onStream nextPutByte:HEAD_OS_CODE. |
706 flags := onStream nextByte. |
737 ]. |
707 (flags bitAnd:HEAD_RESERVED) ~~ 0 ifTrue:[ |
|
708 self zerror:'wrong data format' |
|
709 ]. |
|
710 |
|
711 "discard time, xflags and OS code" |
|
712 onStream skip:6. |
|
713 |
|
714 (flags bitAnd:HEAD_EXTRA_FIELD) ~~ 0 ifTrue:[|len| |
|
715 "skip the extra field" |
|
716 len := onStream nextByte + (onStream nextByte bitShift:8). |
|
717 len timesRepeat:[ onStream nextByte ]. |
|
718 ]. |
|
719 |
|
720 (flags bitAnd:HEAD_ORIG_NAME) ~~ 0 ifTrue:[|b| |
|
721 "skip the original file name" |
|
722 [ (b := onStream nextByte) ~~ 0 ] whileTrue. |
|
723 ]. |
|
724 |
|
725 (flags bitAnd:HEAD_CRC) ~~ 0 ifTrue:[ |
|
726 "skip the header crc" |
|
727 onStream skip:2. |
|
728 ]. |
|
729 ! |
|
730 |
|
731 writeHeader |
|
732 "write the gzip magic id" |
|
733 |
|
734 GZ_MAGIC_ID do:[:b| onStream nextPutByte:b ]. |
|
735 |
|
736 "write the method" |
|
737 onStream nextPutByte:Z_DEFLATED. |
|
738 |
|
739 "write the flags" |
|
740 onStream nextPutByte:0. |
|
741 |
|
742 "write time" |
|
743 4 timesRepeat:[ onStream nextPutByte:0 ]. |
|
744 |
|
745 "write xflags" |
|
746 onStream nextPutByte:0. |
|
747 |
|
748 "write OS code" |
|
749 onStream nextPutByte:HEAD_OS_CODE. |
738 ! ! |
750 ! ! |
739 |
751 |
740 !ZipStream class methodsFor:'documentation'! |
752 !ZipStream class methodsFor:'documentation'! |
741 |
753 |
742 version |
754 version |
743 ^ '$Header: /cvs/stx/stx/libbasic2/ZipStream.st,v 1.29 2008-06-05 09:16:16 ab Exp $' |
755 ^ '$Header: /cvs/stx/stx/libbasic2/ZipStream.st,v 1.30 2008-06-30 09:07:57 cg Exp $' |
744 ! ! |
756 ! ! |
745 |
757 |
746 ZipStream initialize! |
758 ZipStream initialize! |