Package: ratarmount
Random Access Tar Mount (Ratarmount)Ratarmount collects all file positions inside a TAR so that it can easily jump to and read from any file without extracting it.
It, then,mountstheTARusingfusepyfor read access just likearchivemount.
Incontrasttolibarchive, on which archivemount is based, random access and true seeking is supported.
And in contrast totarindexer, which also collects file positions for random access, ratarmount offers easy access via FUSE and support for compressed TARs.Capabilities:Highly Parallelized:By default, all cores are used for parallelized algorithms like for the gzip, bzip2, and xz decoders.
This can yield huge speedups on most modern processors but requires more main memory.
It can be controlled or completely turned off using the-P <cores>option.Recursive Mounting:Ratarmount will also mount TARs inside TARs inside TARs, ... recursively into folders of the same name, which is useful for the 1.31TB ImageNet data set.Mount Compressed Files:You may also mount files with one of the supported compression schemes.
Even if these files do not contain a TAR, you can leverage ratarmount's true seeking capabilities when opening the mounted uncompressed view of such a file.Read-Only Bind Mounting:Folders may be mounted read-only to other folders for usecases like merging a backup TAR with newer versions of those files residing in a normal folder.Union Mounting:Multiple TARs, compressed files, and bind mounted folders can be mounted under the same mountpoint.Write Overlay:A folder can be specified as write overlay.
All changes below the mountpoint will be redirected to this folder and deletions are tracked so that all changes can be applied back to the archive.TAR compressions supported for random access:BZip2as provided byindexed_bzip2as a backend, which is a refactored and extended version ofbzcatfromtoybox. See also thereverse engineered specification.Gzipas provided byrapidgziporindexed_gzipby Paul McCarthy. See alsoRFC1952.Xzas provided bypython-xzby Rogdham orlzmaffiby Tomer Chachamu. See alsoThe .xz File Format.Zstdas provided byindexed_zstdby Marco Martinelli. See alsoZstandard Compression Format.Other supported archive formats:Raras provided byrarfileby Marko Kreen. See also theRAR 5.0 archive format.Zipas provided byzipfile, which is distributed with Python itself. See also theZIP File Format Specification.Table of ContentsInstallationInstallation via AppImageInstallation via Package ManagerArch LinuxSystem Dependencies for PIP Installation (Rarely Necessary)PIP Package InstallationBenchmarksThe ProblemThe SolutionUsageMetadata Index CacheBind MountingUnion MountingFile versionsCompressed non-TAR filesXz and Zst FilesAs a LibraryInstallationYou can install ratarmount either by simply downloading theAppImageor via pip.
The latter might requireinstalling additional dependencies.pipinstallratarmountInstallation via AppImageTheAppImagefiles are attached under "Assets" on thereleases page.
They require no installation and can be simply executed like a portable executable.
If you want to install it, you can simply copy it into any of the folders listed in yourPATH.wget'https://github.com/mxmlnkn/ratarmount/releases/download/v0.14.0/ratarmount-0.14.0-x86_64.AppImage'chmodu+x'ratarmount-manylinux2014_x86_64.AppImage'./ratarmount-manylinux2014_x86_64.AppImage--help# Simple test runsudocpratarmount-manylinux2014_x86_64.AppImage/usr/local/bin/ratarmount# Example installationInstallation via Package ManagerArch LinuxArch Linux's AUR offers ratarmount asstableanddevelopmentpackage.
Use anAUR helper, likeyayorparu, to install one of them:#stableversionparu -Syu ratarmount#developmentversionparu -Syu ratarmount-gitCondacondainstall-cconda-forgeratarmountSystem Dependencies for PIP Installation (Rarely Necessary)Python 3.6+, preferably pip 19.0+, FUSE, and sqlite3 are required.
These should be preinstalled on most systems.On Debian-like systems like Ubuntu, you can install/update all dependencies using:sudoaptinstallpython3python3-pipfusesqlite3unarOn macOS, you have to installmacFUSEwith:brewinstallmacfuseIf you are installing on a system for which there exists no manylinux wheel, then you'll have to install dependencies required to build from source:sudoaptinstallpython3python3-pipfusebuild-essentialsoftware-properties-commonzlib1g-devlibzstd-devliblzma-devcffiPIP Package InstallationThen, you can simply install ratarmount from PyPI:pipinstallratarmountOr, if you want to test the latest version:python3-mpipinstall--user--force-reinstall\'git+https://github.com/mxmlnkn/ratarmount.git@develop#egginfo=ratarmountcore&subdirectory=core'\'git+https://github.com/mxmlnkn/ratarmount.git@develop#egginfo=ratarmount'If there are troubles with the compression backend dependencies, you can try the pip--no-depsargument.
Ratarmount will work without the compression backends.
The hard requirements arefusepyand for Python versions older than 3.7.0dataclasses.BenchmarksNot shown in the benchmarks, but ratarmount can mount files withpreexisting index sidecar filesin under a second making itvastly more efficientcompared to archivemount for everysubsequent mount.
Also, archivemount has no progress indicator making it very unlikely the user will wait hours for the mounting to finish.
Fuse-archive, an iteration on archivemount, has the--asyncprogressoption to give a progress indicator using the timestamp of a dummy file.
Note that fuse-archive daemonizes instantly but the mount point will not be usable for a long time and everything trying to use it will hang until then when not using--asyncprogress!Getting file contentsof a mounted archive is generallyvastly fasterthan archivemount and fuse-archive and does not increase with the archive size or file count resulting in the largest observed speedups to be around 5 orders of magnitude!Memory consumptionof ratarmount is mostlylessthan archivemount and mostly does not grow with the archive size.
Not shown in the plots, but the memory usage will be much smaller when not specifying-P 0, i.e., when not parallelizing.
The gzip backend grows linearly with the archive size because the data for seeking is thousands of times larger than the simple two 64-bit offsets required for bzip2.
The memory usage of the zstd backend only seems humongous because it usesmmapto open.
The memory used bymmapis not even counted as used memory when showing the memory usage withfreeorhtop.For empty files, mounting with ratarmount and archivemount does not seem be bounded by decompression nor I/O bandwidths but instead by the algorithm for creating the internal file index.
This algorithm scaleslinearlyfor ratarmount and fuse-archive but seems to scale worse than even quadratically for archives containing more than 1M files when using archivemount.
Ratarmount 0.10.0 improves upon earlier versions by batching SQLite insertions.Mountingbzip2andxzarchives has actually becomefasterthan archivemount and fuse-archive withratarmount -P 0on most modern processors because it actually uses more than one core for decoding those compressions.indexed_bzip2supports blockparallel decodingsince version 1.2.0.Gzipcompressed TAR files are two times slower than archivemount during first time mounting.
It is not totally clear to me why that is because streaming the file contents after the archive being mounted is comparably fast, see the next benchmarks below.
In order to have superior speeds for both of these, I amexperimentingwith a parallelized gzip decompressor like the prototypepugzoffers for non-binary files only.For the other cases, mounting times become roughly the same compared to archivemount for archives with 2M files in an approximately 100GB archive.Getting a lot of metadatafor archive contents as demonstrated by callingfindon the mount point is an order of magnitudeslowercompared to archivemount. Because the C-based fuse-archive is even slower than ratarmount, the difference is very likely that archivemount uses the low-level FUSE interface while ratarmount and fuse-archive use the high-level FUSE interface.Reading files from the archive with archivemount are scaling quadratically instead of linearly.
This is because archivemount starts reading from the beginning of the archive for each requested I/O block.
The block size depends on the program or operating system and should be in the order of 4 kiB.
Meaning, the scaling isO( (sizeOfFileToBeCopiedFromArchive / readChunkSize)^2 ).
Both, ratarmount and fuse-archive avoid this behavior.
Because of this quadratic scaling, the average bandwidth with archivemount seems like it decreases with the file size.Reading bz2 and xz are both an order of magnitude faster, as tested on my 12/24-core Ryzen 3900X, thanks to parallelization.Memory is bounded in these tests for all programs but ratarmount is a lot more lax with memory because it uses a Python stack and because it needs to hold caches for a constant amount of blocks for parallel decoding of bzip2 and xz files.
The zstd backend in ratarmount looks unbounded because it uses mmap, whose memory usage will automatically stop and be freed if the memory limit has been reached.The peak for the xz decoder reading speeds happens because some blocks will be cached when loading the index, which is not included in the benchmark for technical reasons. The value for the 1 GiB file size is more realistic.Further benchmarks can be viewedhere.The ProblemYou downloaded a large TAR file from the internet, for example the1.31TBlargeImageNet, and you now want to use it but lack the space, time, or a file system fast enough to extract all the 14.2 million image files.Existing Partial SolutionsPartial SolutionsArchivemountArchivemountseems to have large performance issues for too many files and large archive for both mounting and file access in version 0.8.7. A more in-depth comparison benchmark can be foundhere.Mounting the 6.5GB ImageNet Large-Scale Visual Recognition Challenge 2012 validation data set, and then testing the speed with:time cat mounted/ILSVRC2012_val_00049975.JPEG | wc -ctakes 250ms for archivemount and 2ms for ratarmount.Trying to mount the 150GBILSVRC object localization data setcontaining 2 million images was given up upon after 2 hours. Ratarmount takes ~15min to create a ~150MB index and <1ms for opening an already created index (SQLite database) and mounting the TAR. In contrast, archivemount will take the same amount of time even for subsequent mounts.Does not support recursive mounting. Although, you could write a script to stack archivemount on top of archivemount for all contained TAR files.TarindexerTarindexis a command line to tool written in Python which can create index files and then use the index file to extract single files from the tar fast. However, it also has some caveats which ratarmount tries to solve:It only works with single files, meaning it would be necessary to loop over the extract-call. But this would require loading the possibly quite large tar index file into memory each time. For example for ImageNet, the resulting index file is hundreds of MB large. Also, extracting directories will be a hassle.It's difficult to integrate tarindexer into other production environments. Ratarmount instead uses FUSE to mount the TAR as a folder readable by any other programs requiring access to the contained data.Can't handle TARs recursively. In order to extract files inside a TAR which itself is inside a TAR, the packed TAR first needs to be extracted.TAR BrowserI didn't find out aboutTAR Browserbefore I finished the ratarmount script. That's also one of it's cons:Hard to find. I don't seem to be the only one who has trouble finding it as it has one star on Github after 7 years compared to 45 stars for tarindexer after roughly the same amount of time.Hassle to set up. Needs compilation and I gave up when I was instructed to set up a MySQL database for it to use. Confusingly, the setup instructions are not on its Github buthere.Doesn't seem to support recursive TAR mounting. I didn't test it because of the MysQL dependency but the code does not seem to have logic for recursive mounting.Xz compression also is only block or frame based, i.e., only works faster with files created bypixzorpxz.Pros:supports bz2- and xz-compressed TAR archivesThe SolutionRatarmount creates an index file with file names, ownership, permission flags, and offset information.
This sidecar is stored at the TAR file's location or in~/.ratarmount/.
Ratarmount can load that index file in under a second if it exists and then offers FUSE mount integration for easy access to the files inside the archive.Here is a more recent test for version 0.2.0 with the new default SQLite backend:TAR size: 124GBContains TARs: yesFiles in TAR: 1000Files in TAR (including recursively in contained TARs): 1.26 millionIndex creation (first mounting): 15m 39sIndex size: 146MBIndex loading (subsequent mounting): 0.000sReading a 64kB file: ~4msRunning 'find mountPoint -type f | wc -l' (1.26M stat calls): 1m 50sThe reading time for a small file simply verifies the random access by using file seek to be working. The difference between the first read and subsequent reads is not because of ratarmount but because of operating system and file system caches.Older test with 1.31 TB Imagenet (Fall 2011 release)The test with the first version of ratarmount (50e8dbb), which used the, as of now removed, pickle backend for serializing the metadata index, for theImageNet data set:TAR size: 1.31TBContains TARs: yesFiles in TAR: ~26 000Files in TAR (including recursively in contained TARs): 14.2 millionIndex creation (first mounting): 4 hoursIndex size: 1GBIndex loading (subsequent mounting): 80sReading a 40kB file: 100ms (first time) and 4ms (subsequent times)Index loading is relatively slow with 80s because of the pickle backend, which now has been replaced with SQLite and should take less than a second now.UsageCommand Line OptionsSeeratarmount --help.Full command line optionsusage:ratarmount.py[-h][-c][-r][-u][-PPARALLELIZATION][-v][--passwordPASSWORD][--verify-mtime][--index-fileINDEX_FILE][--index-foldersINDEX_FOLDERS][--recursion-depthRECURSION_DEPTH][-l][-s][--transform-recursive-mount-pointREGEX_PATTERNREPLACEMENT][-eENCODING][-i][--gnu-incremental][--no-gnu-incremental][--detect-gnu-incremental][-wWRITE_OVERLAY][--commit-overlay][-oFUSE][-f][-dDEBUG][-gsGZIP_SEEK_POINT_SPACING][-pPREFIX][--password-filePASSWORD_FILE][--use-backendUSE_BACKEND][--oss-attributions][--disable-union-mount][--union-mount-cache-max-depthUNION_MOUNT_CACHE_MAX_DEPTH][--union-mount-cache-max-entriesUNION_MOUNT_CACHE_MAX_ENTRIES][--union-mount-cache-timeoutUNION_MOUNT_CACHE_TIMEOUT][--index-minimum-file-countINDEX_MINIMUM_FILE_COUNT][--transformREGEX_PATTERNREPLACEMENT]mount_source[mount_source...][mount_point]Withratarmount,youcan:-Mounta(compressed)TARfiletoafolderforread-onlyaccess-Mountacompressedfileto`<mountpoint>/<filename>`-Bindmountafoldertoanotherfolderforread-onlyaccess-UnionmountalistofTARs,compressedfiles,andfolderstoamountpointforread-onlyaccessOptionalArguments:--passwordPASSWORDSpecifyasinglepasswordwhichshallbeusedforRARandZIPfiles.(default:)-PPARALLELIZATION,--parallelizationPARALLELIZATIONIfanintegerotherthan1isspecified,thenthethreadedparallelbzip2decoderwillbeusedspecifiedamountofblockdecoderthreads.Furtherthreadswithlighterworkmaybestarted.Avalueof0willusealltheavailablecores(24).(default:0)-h,--helpShowthishelpmessageandexit.-r,--recursiveMountarchivesinsidearchivesrecursively.Sameas--recursion-depth-1.(default:False)-u,--unmountUnmountthegivenmountpoint.Equivalenttocalling"fusermount -u".(default:False)-v,--versionPrintversioninformationandexit.PositionalOptions:mount_sourceThepathtotheTARarchivetobemounted.Ifmultiplearchivesand/orfoldersarespecified,thentheywillbemountedasiftheargumentscomingfirstwereupdatedwiththecontentsofthearchivesorfoldersspecifiedthereafter,i.e.,thelistofTARsandfolderswillbeunionmounted.mount_pointThepathtoafoldertomounttheTARcontentsinto.Ifnomountpathisspecified,theTARwillbemountedtoafolderofthesamenamebutwithoutafileextension.(default:None)IndexOptions:--index-fileINDEX_FILESpecifyapathtothe.index.sqlitefile.Settingthiswilldisablefallbackindexfolders.Ifthegivenpathis":memory:",thentheindexwillnotbewrittenouttodisk.(default:None)--index-foldersINDEX_FOLDERSSpecifyoneormultiplepathsforstoring.index.sqlitefiles.Pathswillbetestedforsuitabilityinthegivenorder.AnemptypathwillbeinterpretedasthelocationinwhichtheTARresides.Iftheargumentbeginswithabracket"[",thenitwillbeinterpretedasaJSON-formattedlist.Iftheargumentcontainsacomma",",itwillbeinterpretedasacomma-separatedlistoffolders.Else,thewholestringwillbeinterpretedasonefolderpath.Examples:--index-folders",~/.foo"willtrytosavebesidestheTARandifthatdoesnotwork,in~/.foo.--index-folders'["~/.ratarmount","foo,9000"]'willnevertrytosavebesidestheTAR.--index-folder~/.ratarmountwillonlytest~/.ratarmountasastoragelocationandnothingelse.Instead,itwillfirsttry~/.ratarmountandthefolder"foo,9000".(default:,~/.cache/ratarmount,~/.ratarmount)--verify-mtimeBydefault,onlytheTARfilesizeischeckedtomatchtheoneinthefoundexistingratarmountindex.Ifthisoptionisspecified,thenalsocheckthemodificationtimestamp.Butbewarethatthemtimemightchangeduringcopyingordownloadingwithoutthecontentschanging.So,thischeckmightcausefalsepositives.(default:False)-c,--recreate-indexIfspecified,pre-existing.indexfileswillbedeletedandnewlycreated.(default:False)RecursionOptions:--recursion-depthRECURSION_DEPTHThisoptiontakesprecedenceover--recursive.Mountarchivesinsidethemountedarchivesrecursivelyuptothegivendepth.Anegativevaluerepresentsinfinitedepth.Avalueof0willturnoffrecursion(sameasnotspecifying--recursiveinthefirstplace).Avalueof1willrecursivelymountallarchivesinthegivenarchivesbutnotanydeeper.Notethatthisonlyhasaneffectwhencreatinganindex.Ifanindexalreadyexists,thenthisoptionwillbeeffectivelyignored.Recreatetheindexifyouwantchangetherecursivemountingpolicyanyways.(default:None)--transform-recursive-mount-pointREGEX_PATTERNREPLACEMENTSpecifyaregexpatternandareplacementstring,whichwillbeappliedviaPython'sremoduletothefullpathofthearchivetoberecursivelymounted.E.g.,iftherearerecursivearchives:/folder/archive.tar.gz,youcansubstitute'[.][^/]+$'to''anditwillbemountedto/folder/archive.tar.Oryoucanreplace'^.*/([^/]+).tar.gz$'to'/'tomountallrecursivefoldersunderthetop-levelwithoutextensions.(default:None)-l,--lazyWhenusedwithrecursivelybind-mountedfolders,TARfilesinsidethemountedfolderwillonlybemountedonfirstaccesstoit.(default:False)-s,--strip-recursive-tar-extensionIftrue,thenrecursivelymountedTARsnamed<file>.tarwillbemountedat<file>/.Thismightleadtofoldersofthesamenamebeingoverwritten,sousewithcare.Theindexneedstobe(re)createdtoapplythisoption!(default:False)TarOptions:--detect-gnu-incrementalIfspecified,willautomaticallytrytodetectGNUtarincrementalfilesand,ifso,willstripoctalmodificationprefixes.Notethatthisisonlyaheuristicderivedbytesting1000-10000fileentries.IfyouaresureitisanincrementalTAR,use--gnu-incrementalinstead.(default:False)--gnu-incrementalWillstripoctalmodificationtimeprefixesfromfilepaths,whichappearinGNUincrementalbackupscreatedwithGNUtarwiththe--incrementalor--listed-incrementaloptions.(default:False)--no-gnu-incrementalIfspecified,willneverstripoctalmodificationprefixesandwillalsonotdoautomaticdetection.(default:False)-eENCODING,--encodingENCODINGSpecifyaninputencodingusedforfilenamesamongothersintheTAR.Thismustbeusedwhen,e.g.,tryingtoopenalatin1encodedTARonanUTF-8system.Possibleencodings:https://docs.python.org/3/library/codecs.html#standard-encodings (default:utf-8)-i,--ignore-zerosIgnorezeroedblocksinarchive.Normally,twoconsecutive512-blocksfilledwithzeroesmeanEOFandratarmountstopsreadingafterencounteringthem.Thisoptioninstructsittoreadfurtherandisusefulwhenreadingarchivescreatedwiththe-Aoption.(default:False)WriteOverlayOptions:--commit-overlayApplydeletionsandcontentmodificationsdoneinthewriteoverlaytothearchive.(default:False)-wWRITE_OVERLAY,--write-overlayWRITE_OVERLAYSpecifyanexistingfoldertobeusedasawriteoverlay.Thefolderitselfwillbeunion-mountedontopsuchthatfilesinthisfoldertakeprecedenceoverallotherexistingones.Furthermore,allfilecreationsandmodificationswillbeforwardedtofilesinthisfolder.ModifyingafileinsideaTARwillcopythatfiletotheoverlayfolderandapplythemodificationtothatwritablecopy.Deletingfilesorfolderswillupdatethehiddenmetadatadatabaseinsidetheoverlayfolder.(default:None)AdvancedOptions:--disable-union-mountMountsallspecifiedarchivesinequallynamedsubfoldersunderthemountpoint.(default:False)--index-minimum-file-countINDEX_MINIMUM_FILE_COUNTCreateindexesforarchiveswithfewerthanthislimitoffilesinmemoryinsteadofcreatinga.index.sqlitefile.ThisiscurrentlynotappliedforTARfilesbecausethefilecountonlybecomesknownafterparsingthearchive,forwhichanindexisalreadycreated.(default:1000)--oss-attributionsShowlicensesofusedlibraries.--password-filePASSWORD_FILESpecifyafilewithnewlineseparatedpasswordsforRARandZIPfiles.Thepasswordswillbetriedoutinorderofappearanceinthefile.(default:)--transformREGEX_PATTERNREPLACEMENTSpecifyaregexpatternandareplacementstring,whichwillbeappliedviaPython'sremoduletothefullpathsofallarchivefiles.(default:None)--union-mount-cache-max-depthUNION_MOUNT_CACHE_MAX_DEPTHMaximumnumberoffolderlevelstodescendforbuildingtheunionmountcache.(default:1024)--union-mount-cache-max-entriesUNION_MOUNT_CACHE_MAX_ENTRIESMaximumnumberofpathsbeforestoppingtodescendintosubfolderswhenbuildingtheunionmountcache.(default:100000)--union-mount-cache-timeoutUNION_MOUNT_CACHE_TIMEOUTTimeoutinsecondsbeforestoppingtobuildtheunionmountcache.(default:60)--use-backendUSE_BACKENDSpecifyabackendtobeusedwithhigherpriorityforfileswhichmightbeopenedwithmultiplebackends.Argumentsspecifiedlastwillhavethehighestpriority.Acomma-separatedlistmaybespecified.Possiblebackends:['indexed_bzip2','indexed_gzip','indexed_zstd','lzmaffi','rapidgzip','rarfile','xz','zipfile'](default:None)-dDEBUG,--debugDEBUGSetsthedebugginglevel.Highermeansmoreoutput.Currently,3isthehighest.(default:1)-f,--foregroundKeepsthepythonprograminforegroundsoitcanprintdebugoutputwhenthemountedpathisaccessed.(default:False)-gsGZIP_SEEK_POINT_SPACING,--gzip-seek-point-spacingGZIP_SEEK_POINT_SPACINGThisonlyisappliedwhentheindexisfirstcreatedorrecreatedwiththe-coption.ThespacinggiveninMiBspecifiestheseekpointdistanceintheuncompresseddata.Adistanceof16MiBmeansthatarchivessmallerthan16MiBinuncompressedsizewillnotbenefitfromfasterseektimes.Aseekpointtakesroughly32kiB.So,smallerdistancesleadtomoreresponsiveseekingbutmayexplodetheindexsize!(default:16)-oFUSE,--fuseFUSECommaseparatedFUSEoptions.See"man mount.fuse"forhelp.Example:--fuse"allow_other,entry_timeout=2.8,gid=0".(default:)-pPREFIX,--prefixPREFIX[deprecated]Use"-o modules=subdir,subdir=<prefix>"instead.ThisstandardwayutilizesFUSEitselfandwillalsoworkforotherFUSEapplications.So,itispreferableevenifabitmoreverbose.ThespecifiedpathtothefolderinsidetheTARwillbemountedtoroot.Thiscanbeusefulwhenthearchiveascreatedwithabsolutepaths.E.g.,foranarchivecreatedwith`tar-Pcf/var/log/apt/history.log`,-p/var/log/apt/canbespecifiedsothatthemounttargetdirectory>directly<containshistory.log.(default:)Metadata Index CacheIn order to reduce the mounting time, the created index for random access
to files inside the tar will be saved to one of these locations. These
locations are checked in order and the first, which works sufficiently, will
be used. This is the default location order:.index.sqlite~/.ratarmount/<path to tar: '/' -> '_'>.index.sqlite
E.g., ~/.ratarmount/_media_cdrom_programm.tar.index.sqliteThis list of fallback folders can be overwritten using the--index-foldersoption. Furthermore, an explicitly named index file may be specified using
the--index-fileoption. If--index-fileis used, then the fallback
folders, including the default ones, will be ignored!Bind MountingThe mount sources can be TARs and/or folders.  Because of that, ratarmount
can also be used to bind mount folders read-only to another path similar tobindfsandmount --bind. So, for:ratarmount folder mountpointall files infolderwill now be visible in mountpoint.Union MountingIf multiple mount sources are specified, the sources on the right side will be
added to or update existing files from a mount source left of it. For example:ratarmount folder1 folder2 mountpointwill make both, the files from folder1 and folder2, visible in mountpoint.
If a file exists in both multiple source, then the file from the rightmost
mount source will be used, which in the above example would befolder2.If you want to update / overwrite a folder with the contents of a given TAR,
you can specify the folder both as a mount source and as the mount point:ratarmount folder file.tar folderThe FUSE option -o nonempty will be automatically added if such a usage is
detected. If you instead want to update a TAR with a folder, you only have to
swap the two mount sources:ratarmount file.tar folder folderFile versionsIf a file exists multiple times in a TAR or in multiple mount sources, then
the hidden versions can be accessed through special .versions folders.
For example, consider:ratarmount folder updated.tar mountpointand the filefooexists both in the folder and as two different versions
inupdated.tar. Then, you can list all three versions using:ls -la mountpoint/foo.versions/
    dr-xr-xr-x 2 user group     0 Apr 25 21:41 .
    dr-x------ 2 user group 10240 Apr 26 15:59 ..
    -r-x------ 2 user group   123 Apr 25 21:41 1
    -r-x------ 2 user group   256 Apr 25 21:53 2
    -r-x------ 2 user group  1024 Apr 25 22:13 3In this example, the oldest version has only 123 bytes while the newest and
by default shown version has 1024 bytes. So, in order to look at the oldest
version, you can simply do:cat mountpoint/foo.versions/1Note that these version numbers are the same as when used with tar's--occurrence=Noption.Prefix RemovalUseratarmount -o modules=subdir,subdir=<prefix>to remove path prefixes
using the FUSEsubdirmodule. Because it is a standard FUSE feature, the-o ...argument should also work for other FUSE applications.When mounting an archive created with absolute paths, e.g.,tar -P cf /var/log/apt/history.log, you would see the wholevar/log/apthierarchy under the mount point. To avoid that, specified prefixes can be
stripped from paths so that the mount target directorydirectlycontainshistory.log. Useratarmount -o modules=subdir,subdir=/var/log/apt/to do
so. The specified path to the folder inside the TAR will be mounted to root,
i.e., the mount point.Compressed non-TAR filesIf you want a compressed file not containing a TAR, e.g.,foo.bz2, then
you can also use ratarmount for that. The uncompressed view will then be
mounted to<mountpoint>/fooand you will be able to leverage ratarmount's
seeking capabilities when opening that file.Xz and Zst FilesIn contrast to bzip2 and gzip compressed files, true seeking on xz and zst files is only possible at block or frame boundaries.
This wouldn't be noteworthy, if both standard compressors forxzandzstdwere not by default creating unsuited files.
Even though both file formats do support multiple frames and xz even contains a frame table at the end for easy seeking, both compressors write only a single frame and/or block out, making this feature unusable.
In order to generate truly seekable compressed files, you'll have to usepixzfor xz files.
For zstd compressed, you can try witht2sz.
The standard zstd tool does not support setting smaller block sizes yet although anissuedoes exist.
Alternatively, you can simply split the original file into parts, compress those parts, and then concatenate those parts together to get a suitable multiframe zst file.
Here is a bash function, which can be used for that:Bash script: createMultiFrameZstdcreateMultiFrameZstd()(# Detect being piped intoif[-t0];thenfile=$1frameSize=$2if[[!-f"$file"]];thenecho"Could not find file '$file'."1>&2;return1;fifileSize=$(stat-c%s--"$file")elseif[-t1];thenecho'You should pipe the output to somewhere!'1>&2;return1;fiecho'Will compress from stdin...'1>&2frameSize=$1fiif[[!$frameSize=~^[0-9]+$]];thenecho"Frame size '$frameSize' is not a valid number."1>&2return1fi# Create a temporary file. I avoid simply piping to zstd# because it wouldn't store the uncompressed size.if[[-d/dev/shm]];thenframeFile=$(mktemp--tmpdir=/dev/shm);fiif[[-z$frameFile]];thenframeFile=$(mktemp);fiif[[-z$frameFile]];thenecho"Could not create a temporary file for the frames."1>&2return1fiif[-t0];thentrue>"$file.zst"for((offset=0;offset<fileSize;offset+=frameSize));doddif="$file"of="$frameFile"bs=$((1024*1024))\iflag=skip_bytes,count_bytesskip="$offset"count="$frameSize"2>/dev/nullzstd-c-q--"$frameFile">>"$file.zst"doneelsewhiletrue;doddof="$frameFile"bs=$((1024*1024))\iflag=count_bytescount="$frameSize"2>/dev/null# pipe is finished when reading it yields no further dataif[[!-s"$frameFile"]];thenbreak;fizstd-c-q--"$frameFile"donefi'rm'-f--"$frameFile")In order to compress a file namedfoointo a multiframe zst file calledfoo.zst, which contains frames sized 4MiB of uncompressed ata, you would call it like this:createMultiFrameZstdfoo$((4*1024*1024))It also works when being piped to. This can be useful for recompressing files to avoid having to decompress them first to disk.lbzip2-cdwell-compressed-file.bz2|createMultiFrameZstd$((4*1024*1024))>recompressed.zstWritable MountingThe--write-overlay <folder>option can be used to create a writable mount point.
The original archive will not be modified.File creations will create these files in the specified overlay folder.File deletions and renames will be registered in a database that also resides in the overlay folder.File modifications will copy the file from the archive into the overlay folder before applying the modification.This overlay folder can be stored alongside the archive or it can be deleted after unmounting the archive.
This is useful when building the executable from a source tarball without extracting.
After installation, the intermediary build files residing in the overlay folder can be safely removed.If it is desired to apply the modifications to the original archive, then the--commit-overlaycan be prepended to the original ratarmount call.Here is an example for applying modifications to a writable mount and then committing those modifications back to the archive:Mount it with a write overlay and add new files. The original archive is not modified.ratarmount--write-overlayexample-overlayexample.tarexample-mount-pointecho"Hello World">example-mount-point/new-file.txtUnmount. Changes persist solely in the overlay folder.fusermount-uexample-mount-pointCommit changes to the original archive.ratarmount--commit-overlay--write-overlayexample-overlayexample.tarexample-mount-pointOutput:Tocommittheoverlayfoldertothearchive,thesecommandshavetobeexecuted:tar--delete--null--verbatim-files-from--files-from='/tmp/tmp_ajfo8wf/deletions.lst'\--file'example.tar'2>&1|sed'/^tar: Exiting with failure/d; /^tar.*Not found in archive/d'tar--append-C'zlib-wiki-overlay'--null--verbatim-files-from--files-from='/tmp/tmp_ajfo8wf/append.lst'--file'example.tar'Committingisanexperimentalfeature!
Pleaseconfirmbyentering"commit".Anyotherinputwillcancel.
>Committedsuccessfully.Youcannowremovetheoverlayfolderatexample-overlay.Verify the modifications to the original archive.tar-tvlfexample.tarOutput:-rw-rw-r-- user/user 652817 2022-08-08 10:44 example.txt
-rw-rw-r-- user/user     12 2023-02-16 09:49 new-file.txtRemove the obsole write overlay folder.rm-rexample-overlayAs a LibraryRatarmount can also be used as a library.
Usingratarmountcore, files inside archives can be accessed directly from Python code without requiring FUSE.
For a more detailed description, see theratarmountcore readme here.