The Trunk: Compression-ar.23.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-ar.23.mcz

commits-2
Andreas Raab uploaded a new version of Compression to project The Trunk:
http://source.squeak.org/trunk/Compression-ar.23.mcz

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

Name: Compression-ar.23
Author: ar
Time: 6 September 2010, 3:30:52.455 pm
UUID: a7e61341-4f5f-994b-84d9-ae357e9542a9
Ancestors: Compression-ar.22

Move #lastIndexOfPKSignature: from Collections to Compression.

=============== Diff against Compression-ar.22 ===============

Item was changed:
  ----- Method: ZipArchive class>>findEndOfCentralDirectoryFrom: (in category 'constants') -----
  findEndOfCentralDirectoryFrom: stream
  "Seek in the given stream to the end, then read backwards until we find the
  signature of the central directory record. Leave the file positioned right
  before the signature.
 
  Answers the file position of the EOCD, or 0 if not found."
 
  | data fileLength seekOffset pos maxOffset |
  stream setToEnd.
  fileLength := stream position.
  "If the file length is less than 18 for the EOCD length plus 4 for the signature, we have a problem"
  fileLength < 22 ifTrue: [^ self error: 'file is too short'].
 
  seekOffset := 0.
  pos := 0.
  data := ByteArray new: 4100.
  maxOffset := 40960 min: fileLength. "limit search range to 40K"
 
  [
  seekOffset := (seekOffset + 4096) min: fileLength.
  stream position: fileLength - seekOffset.
  data := stream next: (4100 min: seekOffset) into: data startingAt: 1.
+ pos := self lastIndexOfPKSignature: EndOfCentralDirectorySignature in: data.
- pos := data lastIndexOfPKSignature: EndOfCentralDirectorySignature.
  pos = 0 and: [seekOffset < maxOffset]
  ] whileTrue.
 
  ^ pos > 0
  ifTrue: [ | newPos | stream position: (newPos := (stream position + pos - seekOffset - 1)). newPos]
  ifFalse: [0]!

Item was added:
+ ----- Method: ZipArchive class>>lastIndexOfPKSignature:in: (in category 'constants') -----
+ lastIndexOfPKSignature: aSignature in: data
+ "Answer the last index in data where aSignature (4 bytes long) occurs, or 0 if not found"
+ | a b c d |
+ a := aSignature first.
+ b := aSignature second.
+ c := aSignature third.
+ d := aSignature fourth.
+ (data size - 3) to: 1 by: -1 do: [ :i |
+ (((data at: i) = a)
+ and: [ ((data at: i + 1) = b)
+ and: [ ((data at: i + 2) = c)
+ and: [ ((data at: i + 3) = d) ]]])
+ ifTrue: [ ^i ]
+ ].
+ ^0!