write an entire compressed file - Maple Help

Home : Support : Online Help : Programming : Input and Output : File Manipulation : FileTools : FileTools/Compressed/WriteFile

FileTools[Compressed][WriteFile] - write an entire compressed file

 Calling Sequence WriteFile(gzipfilename, data, opts, gzipopts) WriteFile(target in zipfilename, data, opts)

Parameters

 gzipfilename - string data - string or an rtable of hardware datatype numbers target - string zipfilename - string opts - (optional) options as specified below

Description

 • WriteFile is an all-in-one command to open a file, write data in a compressed format, and close the file.
 • For gzip format, 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 filename must be specified. This is done with the syntax target in filename.  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).

Examples

Create a temporary file in gzip format, write data, and retrieve it.

 > file := FileTools[TemporaryFilename](cat(FileTools[TemporaryDirectory](),kernelopts(dirsep),"GZtest-"));
 ${\mathrm{file}}{:=}{"/mnt/tmpfs/mpldoc_slot1/mpldoc1/GZtest-yYoYxV9R"}$ (1)
 > FileTools[Compressed][WriteFile](file, "This is a test");
 ${14}$ (2)
 ${"This is a test"}$ (3)
 > FileTools[Compressed][WriteFile](file, Array(1..50, 0, datatype=integer[1]));
 ${50}$ (4)
 $\left[\begin{array}{c}{\mathrm{1 .. 50}}{\mathrm{Array}}\\ {\mathrm{Data Type:}}{{\mathrm{integer}}}_{{1}}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{Fortran_order}}\end{array}\right]$ (5)
 > FileTools[Remove](file);

Create a temporary file in gzip format, write data, and retrieve it.

 > zipfile := FileTools[TemporaryFilename](cat(FileTools[TemporaryDirectory](),kernelopts(dirsep),"Ziptest-"));
 ${\mathrm{zipfile}}{:=}{"/mnt/tmpfs/mpldoc_slot1/mpldoc1/Ziptest-bx70dpPu"}$ (6)
 > FileTools[Compressed][WriteFile]("inZipName" in zipfile, "This is a zip test");
 ${18}$ (7)
 > FileTools[Compressed][Contents](zipfile);
 $\left[{"inZipName"}\right]$ (8)
 > FileTools[Compressed][WriteFile]("data" in zipfile, "This is a second file");
 ${21}$ (9)
 > FileTools[Compressed][Contents](zipfile);
 $\left[{"inZipName"}{,}{"data"}\right]$ (10)
 ${"This is a second file"}$ (11)
 ${"This is a zip test"}$ (12)