Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: More Macintosh Toolbox /
Chapter 1 - Resource Manager / Resource Manager Reference
Resource Manager Routines / Reading and Writing Partial Resources


WritePartialResource

You can use the WritePartialResource procedure to write part of a resource to disk when working with a small subsection of a large resource.

PROCEDURE WritePartialResource (theResource: Handle; 
                                offset: LongInt; buffer: UNIV Ptr;
                                count: LongInt);
theResource
A handle to a resource.
offset
The beginning of the resource subsection to write, measured in bytes
from the beginning of the resource.
buffer
A pointer to the buffer containing the data to write.
count
The length of the resource subsection to write.
DESCRIPTION
The WritePartialResource procedure writes the data specified by the buffer parameter to the resource subsection identified by the theResource, offset, and count parameters. Your application is responsible for the buffer's memory management.

If the disk or the file is locked, the ResError function returns an appropriate File Manager result code. If you try to write past the end of a resource, the Resource Manager attempts to enlarge the resource. The ResError function returns the result code writingPastEnd if the attempt succeeds. If the Resource Manager cannot enlarge the resource, ResError returns an appropriate File Manager result code. If you pass an invalid value in the offset parameter, ResError returns the result code inputOutOfBounds.

The WritePartialResource procedure tries to write the data from the buffer to disk. If the attempt is successful and the resource data (referenced through the resource's handle) is in memory, ResError returns the result code resourceInMemory. In this situation, be aware that the data of the resource subsection on disk matches the data from the buffer, not the resource data referenced through the resource's handle. If the attempt to write the data from the buffer to the disk fails, ResError returns an appropriate error.

When using partial resource routines, you should call the SetResLoad procedure, specifying FALSE for the load parameter, before you call GetResource. Doing so prevents the Resource Manager from reading the entire resource into memory. Be sure to restore the normal state by calling SetResLoad again, with the load parameter set to TRUE, immediately after you call GetResource.

If you read a partial resource into memory and then change its size, you must use SetResourceSize to change the entire resource's size on disk as necessary before you write the partial resource.

SPECIAL CONSIDERATIONS
The WritePartialResource procedure may move or purge memory blocks in the application heap. Your application should not call this procedure at interrupt time.

ASSEMBLY-LANGUAGE INFORMATION
The trap macro and routine selector for WritePartialResource are
Trap macroSelector
_ResourceDispatch$7002

RESULT CODES
noErr0No error
dskFulErr-34Disk full
resourceInMemory-188Resource already in memory
writingPastEnd-189Writing past end of file
inputOutOfBounds-190Offset or count out of bounds
SEE ALSO
To check for errors, call the ResError function as described on page 1-47.

For descriptions of the GetResource and SetResLoad routines, see page 1-68 and page 1-74, respectively. The SetResourceSize procedure is described next.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
6 JUL 1996