[squeak-dev] The Trunk: Compression-fbs.37.mcz

commits at source.squeak.org commits at source.squeak.org
Wed Jul 17 08:54:09 UTC 2013


Frank Shearar uploaded a new version of Compression to project The Trunk:
http://source.squeak.org/trunk/Compression-fbs.37.mcz

==================== Summary ====================

Name: Compression-fbs.37
Author: fbs
Time: 17 July 2013, 8:50:07.538 am
UUID: 77da886a-a70a-d242-8442-826c9cd67dad
Ancestors: Compression-fbs.36

Recategorise extension methods into either -Archives or -Streams subcategories.

=============== Diff against Compression-fbs.36 ===============

Item was changed:
+ ----- Method: CompiledMethodTrailer>>decodeEmbeddedSourceZip (in category '*Compression-Streams') -----
- ----- Method: CompiledMethodTrailer>>decodeEmbeddedSourceZip (in category '*Compression-KernelExtensions') -----
  decodeEmbeddedSourceZip
  
  	"data is string with method's source code, compressed using zip compression"
  	self decodeZip.!

Item was changed:
+ ----- Method: CompiledMethodTrailer>>decodeTempsNamesZip (in category '*Compression-Streams') -----
- ----- Method: CompiledMethodTrailer>>decodeTempsNamesZip (in category '*Compression-KernelExtensions') -----
  decodeTempsNamesZip
  
  	"data is string with method's temporary names, compressed using zip compression"
  	self decodeZip.!

Item was changed:
+ ----- Method: CompiledMethodTrailer>>decodeZip (in category '*Compression-Streams') -----
- ----- Method: CompiledMethodTrailer>>decodeZip (in category '*Compression-KernelExtensions') -----
  decodeZip
  
  	"data := <trailer> unzip utf8ToSqueak"
  	| len bytes |
  	len := self decodeLengthField.
  	bytes := ByteArray new: len.
  	1 to: len do: [ :i |
  		bytes at: i put: (method at: method size - size + i) ].
  	
  	data := (ZipReadStream on: bytes) contents asString convertFromEncoding: 'utf8'!

Item was changed:
+ ----- Method: CompiledMethodTrailer>>encodeEmbeddedSourceZip (in category '*Compression-Streams') -----
- ----- Method: CompiledMethodTrailer>>encodeEmbeddedSourceZip (in category '*Compression-KernelExtensions') -----
  encodeEmbeddedSourceZip
  
  	"data is string with method's source code, encode it using Zip compression method"
  	self encodeUsingZip
  !

Item was changed:
+ ----- Method: CompiledMethodTrailer>>encodeTempsNamesZip (in category '*Compression-Streams') -----
- ----- Method: CompiledMethodTrailer>>encodeTempsNamesZip (in category '*Compression-KernelExtensions') -----
  encodeTempsNamesZip
  
  	"data is string with method's temporary names, encode it using zip compression"
  	self encodeUsingZip
  	
  	"data is string with method's source code, encoded using qCompress method"
  
  
  !

Item was changed:
+ ----- Method: CompiledMethodTrailer>>encodeUsingZip (in category '*Compression-Streams') -----
- ----- Method: CompiledMethodTrailer>>encodeUsingZip (in category '*Compression-KernelExtensions') -----
  encodeUsingZip
  
  	"data is string, encode it using gzip compression"
  	| utf8str stream length encodedLength |
  
  	self assert: (data isString).
  	utf8str := data convertToEncoding: 'utf8'.
  	
  	stream := ((ZipWriteStream on: (ByteArray new: utf8str size))
  		nextPutAll: utf8str asByteArray;
  		close;
  		encodedStream).
  		
  	length := stream position.
  	encodedLength := self encodeLengthField: length.
  
  	stream nextPutAll: encodedLength.
  	"trailing byte"
  	stream nextPut: (self kindAsByte + encodedLength size - 1).
  	
  	encodedData := stream contents
  	!

Item was changed:
+ ----- Method: FileStream>>viewGZipContents (in category '*Compression-Streams') -----
- ----- Method: FileStream>>viewGZipContents (in category '*Compression') -----
  viewGZipContents
  	"View the contents of a gzipped file"
  
  	| stringContents |
  	self binary.
  	stringContents := self contentsOfEntireFile.
  	stringContents := (GZipReadStream on: stringContents) upToEnd.
  	^ stringContents asString withSqueakLineEndings.!

Item was changed:
+ ----- Method: PositionableStream>>asZLibReadStream (in category '*Compression-Archives') -----
- ----- Method: PositionableStream>>asZLibReadStream (in category '*Compression') -----
  asZLibReadStream
  	^ZLibReadStream on: collection from: position+1 to: readLimit!

Item was changed:
+ ----- Method: ReadWriteStream>>asUnZippedStream (in category '*Compression-Streams') -----
- ----- Method: ReadWriteStream>>asUnZippedStream (in category '*Compression') -----
  asUnZippedStream
  	| isGZip outputStream first strm archive which |
  	"Decompress this file if needed, and return a stream.  No file is written.  File extension may be .gz or anything else.  Also works on archives (.zip, .gZip)."
  
  	strm := self binary.
  	strm isZipArchive ifTrue: [
  		archive := ZipArchive new readFrom: strm.
  		which := archive members detect: [:any | any fileName asLowercase endsWith: '.ttf'] 
  								ifNone: [nil].
  		which ifNil: [archive close.
  					^ self error: 'Can''t find .ttf file in archive'].
  		strm := which contentStream.
  		archive close].
  
  	first := strm next.
  	isGZip := (strm next * 256 + first) = (GZipConstants gzipMagic).
  	strm skip: -2.
  	isGZip 
  		ifTrue: [outputStream := (MultiByteBinaryOrTextStream with:
  									(GZipReadStream on: strm) upToEnd) reset.
  				strm close]
  		ifFalse: [outputStream := strm].
  	^ outputStream!

Item was changed:
+ ----- Method: ReadWriteStream>>isZipArchive (in category '*Compression-Archives') -----
- ----- Method: ReadWriteStream>>isZipArchive (in category '*Compression') -----
  isZipArchive
  	"Determine if this appears to be a valid Zip archive"
  	| sig |
  	self binary.
  	sig := self next: 4.
  	self position: self position - 4. "rewind"
  	^ZipArchive validSignatures includes: sig!

Item was changed:
+ ----- Method: StandardFileStream>>compressFile (in category '*Compression-Streams') -----
- ----- Method: StandardFileStream>>compressFile (in category '*Compression') -----
  compressFile
  	"Write a new file that has the data in me compressed in GZip format."
  	| zipped buffer |
  
  	self readOnly; binary.
  	zipped := self directory newFileNamed: (self name, FileDirectory dot, 'gz').
  	zipped binary; setFileTypeToObject.
  		"Type and Creator not to be text, so can be enclosed in an email"
  	zipped := GZipWriteStream on: zipped.
  	buffer := ByteArray new: 50000.
  	'Compressing ', self fullName 
  		displayProgressFrom: 0 to: self size
  		during: [:bar |
  			[self atEnd] whileFalse: [
  				bar value: self position.
  				zipped nextPutAll: (self nextInto: buffer)].
  			zipped close.
  			self close].
  	^zipped!

Item was changed:
+ ----- Method: String>>unzipped (in category '*Compression-Streams') -----
- ----- Method: String>>unzipped (in category '*Compression') -----
  unzipped
  	| magic1 magic2 |
  	magic1 := (self at: 1) asInteger.
  	magic2 := (self at: 2) asInteger.
  	(magic1 = 16r1F and:[magic2 = 16r8B]) ifFalse:[^self].
  	^(GZipReadStream on: self) upToEnd!

Item was changed:
+ ----- Method: String>>zipped (in category '*Compression-Streams') -----
- ----- Method: String>>zipped (in category '*Compression') -----
  zipped
  	| stream gzstream |
  
  	stream := RWBinaryOrTextStream on: String new.
  
  	gzstream := GZipWriteStream on: stream.
  	gzstream nextPutAll: self.
  	gzstream close.
  	stream reset.
  
  	^ stream contents.
  !



More information about the Squeak-dev mailing list