FileTools[Compressed]
WriteFile
write an entire compressed file
Calling Sequence
Parameters
Options
Description
Examples
Compatibility
WriteFile(gzipfilename, data, opts, gzipopts)
WriteFile(target in zipfilename, data, opts)
gzipfilename
-
string
data
string or an rtable of hardware datatype numbers
target
zipfilename
opts
(optional) options as specified below
format : bzip2, zip, or gzip ; specify the output format explicitly
output : bytes ; write bytes of string input directly to file, even when target ends in ".m" or ".mpl". even
gzipopts : additional compression options to pass to zlib see FileTools[Compressed].
WriteFile is an all-in-one command to open a file, write data in a compressed format, and close the file.
For bzip2 and gzip formats, the default action is to overwrite the target file.
For zip format, the file zipfilename is a container, so a target filename target within the archive zipfilename must be specified. This is done with the syntax target in zipfilename. If target exists in zipfilename already, it will be replaced. Replacing a file in a zip archive will force all other open handles to the same zip file to be closed. If the target does not exist it will be appended to the zip file alongside any other pre-existing data.
By default, the bytes of a string or hardware rtable are compressed and written to the target file. Arbitrary Maple objects, such as non-hardware rtables can be written only if the name of the in-zip file target being written ends in ".m" or ".mpl". In these cases, the Maple data structure is converted to either external save format, or plain text format before writing. Specifying output=bytes will override the filename matching, and always write the bytes of a string or Array (and fail on other objects).
Create a temporary file in gzip format, write data, and retrieve it.
file≔FileToolsTemporaryFilename⁡FileToolsJoinPath⁡FileToolsTemporaryDirectory⁡,GZtest-
file≔/tmp/mpldoc4/GZtest-yYoYxV9R
FileToolsCompressedWriteFile⁡file,This is a test
14
FileToolsCompressedReadFile⁡file,string
This is a test
FileToolsCompressedWriteFile⁡file,Array⁡1..50,0,datatype=integer1
50
FileToolsCompressedReadFile⁡file
00000000000000000000000000000000000000000000000000
FileToolsRemove⁡file
zipfile≔FileToolsTemporaryFilename⁡FileToolsJoinPath⁡FileToolsTemporaryDirectory⁡,Ziptest-
zipfile≔/tmp/mpldoc4/Ziptest-bx70dpPu
FileTools[Compressed][WriteFile]("inZipName" in zipfile, "This is a zip test");
18
FileToolsCompressedContents⁡zipfile
inZipName
FileTools[Compressed][WriteFile]("data" in zipfile, "This is a second file");
21
inZipName,data
FileTools[Compressed][ReadFile]("data" in zipfile, string);
This is a second file
FileTools[Compressed][ReadFile]("inZipName" in zipfile, string);
This is a zip test
FileToolsRemove⁡zipfile
The FileTools[Compressed][WriteFile] command was introduced in Maple 16.
For more information on Maple 16 changes, see Updates in Maple 16.
See Also
FileTools[Compressed][ReadFile]
FileTools[Remove]
Download Help Document