{
    "mode": "perldoc",
    "parameter": "File::RandomAccess",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/File%3A%3ARandomAccess/json",
    "generated": "2026-06-10T16:24:29Z",
    "synopsis": "use File::RandomAccess;\n$raf = new File::RandomAccess(\\*FILE, $disableSeekTest);\n$raf = new File::RandomAccess(\\$data);\n$err = $raf->Seek($pos);\n$num = $raf->Read($buff, $bytes);",
    "sections": {
        "NAME": {
            "content": "File::RandomAccess - Random access reads of sequential file or scalar\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use File::RandomAccess;\n\n$raf = new File::RandomAccess(\\*FILE, $disableSeekTest);\n\n$raf = new File::RandomAccess(\\$data);\n\n$err = $raf->Seek($pos);\n$num = $raf->Read($buff, $bytes);\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Allows random access to sequential file by buffering the file if necessary. Also allows access\nto data in memory to be accessed as if it were a file.\n",
            "subsections": []
        },
        "METHODS": {
            "content": "new Creates a new RandomAccess object given a file reference or reference to data in memory.\n\n# Read from open file or pipe\n$raf = new File::RandomAccess(\\*FILE);\n\n# Read from data in memory\n$raf = new File::RandomAccess(\\$data);\n\nInputs:\n0) Reference to RandomAccess object or RandomAccess class name.\n\n1) File reference or scalar reference.\n\n2) Flag set if file is already random access (disables automatic SeekTest).\n\nReturns:\nReference to RandomAccess object.\n\nSeekTest\nPerforms test seek() on file to determine if buffering is necessary. If the seek() fails,\nthen the file is buffered to allow random access. SeekTest() is automatically called from\nnew unless specified.\n\n$result = $raf->SeekTest();\n\nInputs:\n0) Reference to RandomAccess object.\n\nReturns:\n1 if seek test passed (ie. no buffering required).\n\nNotes:\nMust be called before any other i/o.\n\nTell\nGet current position in file\n\n$pos = $raf->Tell();\n\nInputs:\n0) Reference to RandomAccess object.\n\nReturns:\nCurrent position in file\n\nSeek\nSeek to specified position in file. When buffered, this doesn't quite behave like seek()\nsince it returns success even if you seek outside the limits of the file.\n\n$success = $raf->Seek($pos, 0);\n\nInputs:\n0) Reference to RandomAccess object.\n\n1) Position.\n\n2) Whence (0=from start, 1=from cur pos, 2=from end).\n\nReturns:\n1 on success, 0 otherwise\n\nRead\nRead data from the file.\n\n$num = $raf->Read($buff, 1024);\n\nInputs:\n0) Reference to RandomAccess object.\n\n1) Buffer.\n\n2) Number of bytes to read.\n\nReturns:\nNumber of bytes actually read.\n\nReadLine\nRead a line from file (end of line is $/).\n\nInputs:\n0) Reference to RandomAccess object.\n\n1) Buffer.\n\nReturns:\nNumber of bytes read.\n\nSlurp\nRead whole file into buffer, without changing read pointer.\n\nInputs:\n0) Reference to RandomAccess object.\n\nReturns:\nNothing.\n\nBinMode\nSet binary mode for file.\n\nInputs:\n0) Reference to RandomAccess object.\n\nReturns:\nNothing.\n\nClose\nClose the file and free the buffer.\n\nInputs:\n0) Reference to RandomAccess object.\n\nReturns:\nNothing.\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "NoBuffer\nAvoid buffering sequential files.\n\n$raf->{NoBuffer} = 1;\n\nWhen this option is set, old data is purged from the internal buffer before a read operation\non a sequential file. In this mode, memory requirements may be significantly reduced when\nreading sequential files, but seeking backward is limited to within the size of the internal\nbuffer (which will be at least as large as the last returned data block), and seeking\nrelative to the end of file is not allowed.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Copyright 2003-2022 Phil Harvey (philharvey66 at gmail.com)\n\nThis library is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Image::ExifTool(3pm)\n",
            "subsections": []
        }
    },
    "summary": "File::RandomAccess - Random access reads of sequential file or scalar",
    "flags": [],
    "examples": [],
    "see_also": [
        {
            "name": "ExifTool",
            "section": "3pm",
            "url": "https://www.chedong.com/phpMan.php/man/ExifTool/3pm/json"
        }
    ]
}