The Trunk: Compression-bf.46.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Compression-bf.46.mcz

commits-2
Bert Freudenberg uploaded a new version of Compression to project The Trunk:
http://source.squeak.org/trunk/Compression-bf.46.mcz

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

Name: Compression-bf.46
Author: bf
Time: 8 December 2014, 1:35:04.484 am
UUID: d9f61764-05a9-4109-ae6c-4835e2d04a4a
Ancestors: Compression-nice.45

Restore timestamps lost in assignment conversion.

=============== Diff against Compression-nice.45 ===============

Item was changed:
  ----- Method: CompressedSourceStream>>contentsOfEntireFile (in category 'access') -----
  contentsOfEntireFile
  | contents |
  self position: 0.
  contents := self next: self size.
  self close.
  ^ contents!

Item was changed:
  ----- Method: CompressedSourceStream>>next (in category 'access') -----
  next
  <primitive: 65>
  position >= readLimit
  ifTrue: [^ (self next: 1) at: 1]
  ifFalse: [^ collection at: (position := position + 1)]!

Item was changed:
  ----- Method: CompressedSourceStream>>next: (in category 'access') -----
  next: n
  | str |
  n <= (readLimit - position) ifTrue:
  ["All characters are available in buffer"
  str := collection copyFrom: position + 1 to: position + n.
  position := position + n.
  ^ str].
 
  "Read limit could be segment boundary or real end of file"
  (readLimit + self segmentOffset) = endOfFile ifTrue:
  ["Real end of file -- just return what's available"
  ^ self next: readLimit - position].
 
  "Read rest of segment.  Then (after positioning) read what remains"
  str := self next: readLimit - position.
  self position: self position.
  ^ str , (self next: n - str size)
  !

Item was changed:
  ----- Method: CompressedSourceStream>>openOn: (in category 'open/close') -----
  openOn: aFile
  "Open the receiver."
  segmentFile := aFile.
  segmentFile binary.
  segmentFile size > 0
  ifTrue:
  [self readHeaderInfo.  "If file exists, then read the parameters"]
  ifFalse:
  [self segmentSize: 20000 maxSize: 34000000.  "Otherwise write default values"]!

Item was changed:
  ----- Method: CompressedSourceStream>>position: (in category 'access') -----
  position: newPosition
  | compressedBuffer newSegmentIndex |
  newPosition > endOfFile ifTrue:
  [self error: 'Attempt to position beyond the end of file'].
  newSegmentIndex := (newPosition // segmentSize) + 1.
  newSegmentIndex ~= segmentIndex ifTrue:
  [self flush.
  segmentIndex := newSegmentIndex.
  newSegmentIndex > nSegments ifTrue:
  [self error: 'file size limit exceeded'].
  segmentFile position: (segmentTable at: segmentIndex).
  (segmentTable at: segmentIndex+1) = 0
  ifTrue:
  [newPosition ~= endOfFile ifTrue:
  [self error: 'Internal logic error'].
  collection size = segmentSize ifFalse:
  [self error: 'Internal logic error'].
  "just leave garbage beyond end of file"]
  ifFalse:
  [compressedBuffer := segmentFile next: ((segmentTable at: segmentIndex+1) - (segmentTable at: segmentIndex)).
  collection :=  (GZipReadStream on: compressedBuffer) upToEnd asString].
  readLimit := collection size min: endOfFile - self segmentOffset].
  position := newPosition \\ segmentSize.
  !

Item was changed:
  ----- Method: CompressedSourceStream>>readHeaderInfo (in category 'open/close') -----
  readHeaderInfo
  | valid a b |
  segmentFile position: 0.
  segmentSize := segmentFile nextNumber: 4.
  nSegments := segmentFile nextNumber: 4.
  endOfFile := segmentFile nextNumber: 4.
  segmentFile size < (nSegments+1 + 3 * 4) ifTrue: "Check for reasonable segment info"
  [self error: 'This file is not in valid compressed source format'].
  segmentTable := (1 to: nSegments+1) collect: [:x | segmentFile nextNumber: 4].
  segmentTable first ~= self firstSegmentLoc ifTrue:
  [self error: 'This file is not in valid compressed source format'].
  valid := true.
  1 to: nSegments do:  "Check that segment offsets are ascending"
  [:i | a := segmentTable at: i.  b := segmentTable at: i+1.
  (a = 0 and: [b ~= 0]) ifTrue: [valid := false].
  (a ~= 0 and: [b ~= 0]) ifTrue: [b <= a ifTrue: [valid := false]]].
  valid ifFalse:
  [self error: 'This file is not in valid compressed source format'].
  dirty := false.
  self position: 0.!

Item was changed:
  ----- Method: CompressedSourceStream>>segmentSize:maxSize: (in category 'private') -----
  segmentSize: segSize maxSize: maxSize
  "Note that this method can be called after the initial open, provided that no
  writing has yet taken place.  This is how to override the default segmentation."
  self size = 0 ifFalse: [self error: 'Cannot set parameters after the first write'].
  segmentFile position: 0.
  segmentFile nextNumber: 4 put: (segmentSize := segSize).
  segmentFile nextNumber: 4 put: (nSegments := maxSize // segSize + 2).
  segmentFile nextNumber: 4 put: (endOfFile := 0).
  segmentTable := Array new: nSegments+1 withAll: 0.
  segmentTable at: 1 put: self firstSegmentLoc.  "Loc of first segment, always."
  segmentTable do: [:i | segmentFile nextNumber: 4 put: i].
  segmentIndex := 1.
  collection := String new: segmentSize.
  writeLimit := segmentSize.
  readLimit := 0.
  position := 0.
  endOfFile := 0.
  self writeSegment.
  !

Item was changed:
  ----- Method: CompressedSourceStream>>writeSegment (in category 'private') -----
  writeSegment
  "The current segment must be the last in the file."
  | compressedSegment |
  segmentFile position: (segmentTable at: segmentIndex).
  compressedSegment := ByteArray streamContents:
  [:strm | (GZipWriteStream on: strm) nextPutAll: collection asByteArray; close].
  segmentFile nextPutAll: compressedSegment.
  segmentTable at: segmentIndex + 1 put: segmentFile position.
 
  segmentFile position: 2 * 4.
  segmentFile nextNumber: 4 put: endOfFile.
  segmentFile position: (segmentIndex + 3) * 4.
  segmentFile nextNumber: 4 put: (segmentTable at: segmentIndex + 1).
  dirty := false!

Item was changed:
  ----- Method: GZipSurrogateStream>>timeStamp (in category 'as yet unclassified') -----
  timeStamp
  "Append the current time to the receiver as a String."
  self bufferStream nextChunkPut: "double string quotes and !!s"
  (String streamContents: [:s | Smalltalk timeStamp: s]) printString.
  self bufferStream cr!