2013-08-30 6 views
4

스퀵 스몰 토크에서 디렉토리를 압축하는 방법은 무엇입니까? StandardFileStream에서 compressFile 메서드를 찾았지만 여러 파일이나 디렉터리를 압축하는 방법을 알 수 없습니다. 나는 System-Compression 클래스를 실험했지만 많은 행운이 없었다. 미리 감사드립니다!Squeak Smalltalk에서 디렉토리를 압축하는 방법은 무엇입니까?

이것은 내가 지금 가지고있는 것입니다. 나는 파일 이름 끝에 타임 스탬프를 추가하고있다. 그래서 여기에 주어진 파일 이름으로 시작하는 모든 파일을 zip이나 gzip 파일에 넣고 싶다.

compressFile: aFileName in: aDirectory 

| zipped buffer unzipped zipFileName | 
zipFileName _ aFileName copyUpTo: $. . 
zipped _ aDirectory newFileNamed: (zipFileName, FileDirectory dot, 'zip'). 
zipped binary; setFileTypeToObject. 
zipped _ ZipWriteStream on: zipped. 
buffer _ ByteArray new: 50000. 
aDirectory fileNames do: [:f | 
    (f beginsWith: zipFileName) ifTrue: [ 
     unzipped _ aDirectory readOnlyFileNamed: (aDirectory fullNameFor: f). 
     unzipped binary. 
     [unzipped atEnd] whileFalse:[ 
      zipped nextPutAll: (unzipped nextInto: buffer)]. 
     unzipped close]]. 
zipped close. 
+0

시도해 보았지만 작동하지 않은 코드 스 니펫을 게시 해주십시오. –

+0

방금 ​​내가 가지고있는 것을 추가했습니다. 그것은 실행되지만 터미널에서 압축을 풀려고 할 때이 오류가 발생합니다. End-of-central-directory signature not found. 이 파일은 zip 파일이 이 아니거나 여러 부분으로 된 아카이브 중 하나의 디스크를 구성합니다. 후자의 경우 중앙 보관함 및 zipfile 주석은이 아카이브의 마지막 디스크 에 있습니다. unzip : test1.zip 또는 test1.zip.zip 중 하나에서 zipfile 디렉토리를 찾을 수없고 test1.zip.ZIP, period를 찾을 수 없습니다. –

답변

6

ZipWriteStream, 그것은 적절한 ZIP 파일이 당신은 ZipArchive 클래스를 사용하려는 등 모든 헤더와 디렉토리 정보와 함께 밖으로 누워있다 방법을 알고하지 않는 경우에만 압축에 사용되는 헬퍼 클래스입니다.

"first, construct archive layout in memory" 
zip := ZipArchive new. 
zip addFile: 'foo.txt'. 
zip addFile: 'bar.txt' as: 'xyz.txt'. 
zip addTree: dir match: [:entry | entry name beginswith: 'baz']. 
"then, write archive to disk, compressing each member" 
file := dest newFileNamed: 'test.zip'. 
zip writeTo: file. 
file close. 
+0

도움을 주셔서 감사합니다.하지만 Pharo의 솔루션이라고 생각합니다. Squeak에서 ZipArchive 클래스를 찾을 수 없습니다. –

+1

@Charlotte 어떤 버전의 squeak? 4.x 시리즈에서 ZipArchive는 Compression-Archives 범주로 분류됩니다. –

+0

버전 2를 사용하고 있지만 4로 업그레이드하려고합니다. 감사합니다! –