FileTools[Compressed]

Parameters

 file - string or integer file descriptor type - string or a hardware number type to read number - number of characters or numbers to read

Description

 • The Read command reads a fixed amount of data from a file that has been opened with FileTools[Compressed][Open].

Examples

 > $\mathrm{file}≔\mathrm{FileTools}\left[\mathrm{TemporaryFilename}\right]\left(\mathrm{FileTools}\left[\mathrm{JoinPath}\right]\left(\left[\mathrm{FileTools}\left[\mathrm{TemporaryDirectory}\right]\left(\right),"GZtest-"\right]\right)\right)$
 ${\mathrm{file}}{≔}{"/tmp/mpldoc8/GZtest-yYoYxV9R"}$ (1)
 > $\mathrm{data}≔\mathrm{LinearAlgebra}\left[\mathrm{RandomVector}\right]\left(100,\mathrm{datatype}=\mathrm{float}\left[8\right]\right)$
 ${\mathrm{data}}{≔}\begin{array}{c}\left[\begin{array}{c}{-55.}\\ {17.}\\ {-35.}\\ {36.}\\ {71.}\\ {75.}\\ {47.}\\ {-15.}\\ {-48.}\\ {-38.}\\ {⋮}\end{array}\right]\\ \hfill {\text{100 element Vector[column]}}\end{array}$ (2)
 > $\mathrm{FileTools}\left[\mathrm{Compressed}\right]\left[\mathrm{WriteFile}\right]\left(\mathrm{file},\mathrm{data}\right)$
 ${800}$ (3)
 > $\mathrm{fd}≔\mathrm{FileTools}\left[\mathrm{Compressed}\right]\left[\mathrm{Open}\right]\left(\mathrm{file}\right)$
 ${\mathrm{fd}}{≔}{41206128}$ (4)
 > $\mathrm{FileTools}\left[\mathrm{Compressed}\right]\left[\mathrm{Read}\right]\left(\mathrm{fd},\mathrm{float}\left[8\right],1\right)\left[1\right]$
 ${-55.}$ (5)
 > $\mathrm{FileTools}\left[\mathrm{Compressed}\right]\left[\mathrm{Read}\right]\left(\mathrm{file},\mathrm{float}\left[8\right],99\right)$
 $\left[\begin{array}{ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc}{17.}& {-35.}& {36.}& {71.}& {75.}& {47.}& {-15.}& {-48.}& {-38.}& {-80.}& {48.}& {-13.}& {76.}& {5.}& {-2.}& {5.}& {92.}& {74.}& {-24.}& {-28.}& {-63.}& {-19.}& {-74.}& {83.}& {95.}& {25.}& {-69.}& {27.}& {16.}& {83.}& {81.}& {38.}& {-63.}& {1.}& {-25.}& {-95.}& {-77.}& {-49.}& {-24.}& {-66.}& {-28.}& {-47.}& {87.}& {-99.}& {77.}& {8.}& {-33.}& {49.}& {-63.}& {-25.}& {-1.}& {-31.}& {-88.}& {64.}& {-62.}& {4.}& {69.}& {-63.}& {-87.}& {-34.}& {64.}& {81.}& {25.}& {65.}& {98.}& {51.}& {11.}& {51.}& {95.}& {-11.}& {34.}& {46.}& {9.}& {50.}& {-43.}& {-67.}& {19.}& {29.}& {-12.}& {96.}& {93.}& {-80.}& {-92.}& {-29.}& {96.}& {89.}& {-55.}& {-67.}& {77.}& {-70.}& {13.}& {-58.}& {-94.}& {-7.}& {12.}& {-53.}& {21.}& {-25.}& {40.}\end{array}\right]$ (6)
 > $\mathrm{FileTools}\left[\mathrm{Compressed}\right]\left[\mathrm{Close}\right]\left(\mathrm{fd}\right)$
 ${0}$ (7)
 > $\mathrm{FileTools}\left[\mathrm{Remove}\right]\left(\mathrm{file}\right)$
 > $\mathrm{zipfile}≔\mathrm{FileTools}\left[\mathrm{TemporaryFilename}\right]\left(\mathrm{cat}\left(\mathrm{FileTools}\left[\mathrm{TemporaryDirectory}\right]\left(\right),\mathrm{kernelopts}\left(\mathrm{dirsep}\right),"GZtest-"\right),".zip"\right)$
 ${\mathrm{zipfile}}{≔}{"/tmp/mpldoc8/GZtest-AyUYslLY.zip"}$ (8)
 > FileTools[Compressed][WriteFile]("sample" in zipfile, "A sample message");
 ${16}$ (9)
 > fd := FileTools[Compressed][Open]("sample" in zipfile,'mode'=READ);
 ${\mathrm{fd}}{≔}{1}$ (10)
 > $\mathrm{FileTools}\left[\mathrm{Compressed}\right]\left[\mathrm{Read}\right]\left(\mathrm{fd},\mathrm{string},8\right)$
 ${"A sample"}$ (11)
 > $\mathrm{FileTools}\left[\mathrm{Compressed}\right]\left[\mathrm{Read}\right]\left(\mathrm{fd},\mathrm{string},8\right)$
 ${"message"}$ (12)
 > $\mathrm{FileTools}\left[\mathrm{Compressed}\right]\left[\mathrm{Close}\right]\left(\mathrm{fd}\right)$
 ${0}$ (13)
 > $\mathrm{FileTools}\left[\mathrm{Remove}\right]\left(\mathrm{zipfile}\right)$

Compatibility

 • The FileTools[Compressed][Read] command was introduced in Maple 16.