晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
| DIR:/opt/cloudlinux/alt-php55/root/usr/share/doc/pear/Archive/docs/ |
| Current File : //opt/cloudlinux/alt-php55/root/usr/share/doc/pear/Archive/docs/tutorial.txt |
eZ Components - Archive ~~~~~~~~~~~~~~~~~~~~~~~ .. contents:: Table of Contents Introduction ============ The Archive component provides a generic API for creating and extracting archives. Currently, the Archive component supports the Tar and Zip formats. Compression algorithms, such as GZip or BZip2, are indirectly supported. The stream wrappers from PHP should be used to handle compressed archives. Class overview ============== The following list sums up the most important classes: ezcArchive This class provides the main API for accessing or creating a Tar or Zip archive. ezcArchive provides methods for extracting entries (files, directories, symbolic links and so on), appending entries and removing entries. ezcArchiveEntry The ezcArchiveEntry class is returned when an entry (such as a file or directory) is requested from the opened archive. ezcArchiveEntry provides entry information about the path, its access rights and whether the entry is a directory, a symbolic link, a hard link, a block-file and so on. The owner name, the group name and the last access time are also available. More information about these classes can be found in the documentation of the class itself. Usage ===== The following examples demonstrate how to use the Archive component. Extracting a Tar-archive ------------------------ The Tar format has more than one standard. The most common formats are: - Gnu - POSIX - Unix V7 - Ustar (The default when creating a tar archive) The Archive component can extract from any of these formats. Appending entries to the archive is only available for the Unix V7 and Ustar formats. Extracting entries can occur in two ways: - ezcArchive->extract(), extracts all entries from the archive. - ezcArchive->extractCurrent(), extracts only the current entry. An ezcArchive object can be used like an iterator. After opening the file, it points to the first entry. The iterator can be moved using ezcArchive->next() and ezcArchive->rewind() to move to the next entry or go back to the first entry. The next example demonstrates how to extract an entire archive file-by-file: .. include:: tutorial_extract.php :literal: First, tutorial_autoload.php is included. The included file loads the correct php files for the Archive package. Hereafter the time zone is set to "UTC". The Archive component uses some date functions and might therefore produce warnings if the time zone is not specified. The gzipped Tar archive is opened using the zlib stream. The while() method iterates over each entry, showing the name and extracting the entry itself. The Archive component extends from the PHP Iterator class, thus the above example can be rewritten as follows: .. include:: tutorial_iterator.php :literal: Please be aware that by default archive files are opened in read/write mode. In order to prevent that, you can set an option to open the archive in read-only mode. This also prevents the modify and create timestamps of the file to be preserved. The following example shows that: .. include:: tutorial_read_only.php :literal: Appending files to an archive ----------------------------- Unfortunately, it is not yet possible to directly append files to a gzipped or bzipped Tar archive. The ZLib and BZip2 libraries do not support opening a file for reading and writing. ezcArchive has two methods for appending files: - ezcArchive->append(), appends entries to the end of the archive. - ezcArchive->appendCurrent(), appends entries after the current entry and removes the rest of the files from the archive. To replace the first file as well, use ezcArchive->truncate(). The next example replaces all entries from an existing Zip archive with the files file1.txt and file2.txt: .. include:: tutorial_replacing.php :literal: Appending directories to an archive ----------------------------------- You need to append a slash '/' to the end of the directory name that is added to an archive. The next example replaces all entries from an existing Zip archive with the 'directory' folder and the 'file.txt' file: .. include:: tutorial_directories.php :literal: Appending a directory tree to an archive ---------------------------------------- Using the function ezcBase::walkRecursive() a directory tree can be added to an archive. The next example shows how to browse a directory tree and add all the files and directories inside to an archive: .. include:: tutorial_recursive.php :literal: The **ArchiveContext** class will hold the archive object which is passed to the callback function *findRecursiveCallback*. The *appendRecursive* function sets up the context object (of class **ArchiveContext**) and calls the *findRecursiveCallback* function. In the *findRecursiveCallback* function the current file or directory is appended to the archive object inside the context. More Information ================ For more information, see the ezcArchive API documentation. .. Local Variables: mode: rst fill-column: 79 End: vim: et syn=rst tw=79 |