About SarFiles

Ned Konz ned at squeakland.org
Fri Mar 26 16:51:26 UTC 2004


On Friday 26 March 2004 7:53 am, Raymond Asselin wrote:
> Can a SarFile contains others sarfile with their own
> preamble/postscript ?
>
> For example, say I have a SarFile named: MyImage, which build an
> image with all the facilities I want from a BasicImage, may I put the
> AccuFonts.sar on this MyImage.sar or must I pick each individuals
> elements of the AccuFonts.sar ?
>
> Hope my question is clear.

Sure you can.

However, a couple of things you should note:

* Unless you extract the embedded SARs first to files, you'll have to read 
their contents into memory to install them; for big files you may not want to 
do this.

To install an embedded SAR by extracting it to a file first (recommended for 
big files), you'd put something like this in the 'install/preamble':

	self extractMember: 'AccuFonts.sar'.
	SARInstaller installSAR: 'AccuFonts.sar'.
	FileDirectory default deleteFileNamed: 'AccuFonts.sar'.

To install it from memory, you can do this (note that the same changeset will 
be used):

	SARInstaller new
		directory: FileDirectory default;
		fileInFrom: ((self memberNamed: 'AccuFonts.sar') contentStream).

* Since a SAR is typically compressed, make sure that you don't compress the 
embedded ones again (which will make them bigger!) when you put them into the 
new SAR. That is, when you build the SAR, do this:

	mySar := ZipArchive new.
	member := mySar addFile: 'AccuFonts.sar'.
	member desiredCompressionLevel: 0.

* Make sure that you don't load an older version of a package on top of a 
package that's already loaded!

* If you're packaging this for mass distribution via SqueakMap, consider 
loading the other packages from SqueakMap (after checking for installed 
versions, of course):

	(SMSqueakMap default packageWithName: 'AccuFonts') ifNotNilDo: [ :pkg |
		(pkg installedVersion isNil or: [ pkg installedVersion asVersion < '6' 
asVersion ])
			ifTrue: [ SMSqueakMap default installPackageLatestPublishedNamed: 
'AccuFonts' ]].



Try the script below in a Workspace:
---

sar1 := ZipArchive new.
sar1 addString: 'self inform: ''SAR1, member1.st''.!' as: 'member1.st'.
sar1 addString: 'self fileInMemberNamed: ''member1.st''.' as: 
'install/preamble'.
sar1Stream := RWBinaryOrTextStream on: (ByteArray new: 1000).
sar1 writeTo: sar1Stream.

sar2 := ZipArchive new.
sar2 addString: 'self inform: ''SAR2, member2.st''.!' as: 'member2.st'.
sar2 addString: sar1Stream reset contents as: 'member3.sar'.
sar2 addString: 'self fileInMemberNamed: ''member2.st''.
SARInstaller new directory: FileDirectory default; fileInFrom: ((self 
memberNamed: ''member3.sar'') contentStream).' as: 'install/preamble'.

sar2 writeTo: (FileStream newFileNamed: 'test2.sar').

SARInstaller installSAR: 'test2.sar'

-- 
Ned Konz
http://bike-nomad.com/squeak/



More information about the Squeak-dev mailing list