[Pkg] The Trunk: Compression-nice.43.mcz

commits at source.squeak.org commits at source.squeak.org
Thu Jul 17 20:08:38 UTC 2014


Nicolas Cellier uploaded a new version of Compression to project The Trunk:
http://source.squeak.org/trunk/Compression-nice.43.mcz

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

Name: Compression-nice.43
Author: nice
Time: 17 July 2014, 10:08:21.557 pm
UUID: a211c5be-5c3b-4b74-a09e-65b3a76514f3
Ancestors: Compression-nice.42

Base the String compression support #zipped and #unzipped on ByteArray.

Note 1: surprisingly, compression now seems to work on WideString even if the zipped size is not a multiple of 4... This deserves more testing, but can't be worse than previous behavior which was completely broken.

Note 2: despite the double conversion, working on ByteArray is not slower according to a few naive bench (maybe due to predimensionning of the buffer).

=============== Diff against Compression-nice.42 ===============

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

Item was added:
+ ----- Method: ByteArray>>zipped (in category '*Compression-Streams') -----
+ zipped
+ 	| stream gzstream |
+ 	stream := (ByteArray new: self size // 5) writeStream.
+ 	gzstream := GZipWriteStream on: stream.
+ 	gzstream nextPutAll: self.
+ 	gzstream close.
+ 	^stream contents!

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

Item was changed:
  ----- Method: String>>zipped (in category '*Compression-Streams') -----
  zipped
+ 	"This sounds questionnable for WideString but works - even if zipped size is not a multiple of 4"
+ 	^self isByteString
+ 		ifTrue: [self asByteArray zipped asString]
+ 		ifFalse: [self asByteArray zipped asWideString]!
- 	| stream gzstream |
- 
- 	stream := RWBinaryOrTextStream on: String new.
- 
- 	gzstream := GZipWriteStream on: stream.
- 	gzstream nextPutAll: self.
- 	gzstream close.
- 	stream reset.
- 
- 	^ stream contents.
- !



More information about the Packages mailing list