1File::RandomAccess(3) User Contributed Perl DocumentationFile::RandomAccess(3)
2
3
4

NAME

6       File::RandomAccess - Random access reads of sequential file or scalar
7

SYNOPSIS

9           use File::RandomAccess;
10
11           $raf = new File::RandomAccess(\*FILE, $disableSeekTest);
12
13           $raf = new File::RandomAccess(\$data);
14
15           $err = $raf->Seek($pos);
16           $num = $raf->Read($buff, $bytes);
17

DESCRIPTION

19       Allows random access to sequential file by buffering the file if
20       necessary.  Also allows access to data in memory to be accessed as if
21       it were a file.
22

METHODS

24       new Creates a new RandomAccess object given a file reference or
25           reference to data in memory.
26
27               # Read from open file or pipe
28               $raf = new File::RandomAccess(\*FILE);
29
30               # Read from data in memory
31               $raf = new File::RandomAccess(\$data);
32
33           Inputs:
34               0) Reference to RandomAccess object.
35
36               1) File reference or scalar reference.
37
38               2) flag set if file is already random access (disables
39               automatic SeekTest).
40
41           Returns:
42               Reference to RandomAccess object.
43
44       SeekTest
45           Performs test seek() on file to determine if buffering is
46           necessary.  If the seek() fails, then the file is buffered to allow
47           random access.  SeekTest() is automatically called from new unless
48           specified.
49
50               $result = $raf->SeekTest();
51
52           Inputs:
53               0) Reference to RandomAccess object.
54
55           Returns:
56               1 if seek test passed (ie. no buffering required).
57
58           Notes:
59               Must be called before any other i/o.
60
61       Tell
62           Get current position in file
63
64               $pos = $raf->Tell();
65
66           Inputs:
67               0) Reference to RandomAccess object.
68
69           Returns:
70               Current position in file
71
72       Seek
73           Seek to specified position in file.  When buffered, this doesn't
74           quite behave like seek() since it returns success even if you seek
75           outside the limits of the file.
76
77               $success = $raf->Seek($pos, 0);
78
79           Inputs:
80               0) Reference to RandomAccess object.
81
82               1) Position.
83
84               2) Whence (0=from start, 1=from cur pos, 2=from end).
85
86           Returns:
87               1 on success, 0 otherwise
88
89       Read
90           Read data from the file.
91
92               $num = $raf->Read($buff, 1024);
93
94           Inputs:
95               0) Reference to RandomAccess object.
96
97               1) Buffer.
98
99               2) Number of bytes to read.
100
101           Returns:
102               Number of bytes actually read.
103
104       ReadLine
105           Read a line from file (end of line is $/).
106
107           Inputs:
108               0) Reference to RandomAccess object.
109
110               1) Buffer.
111
112           Returns:
113               Number of bytes read.
114
115       Slurp
116           Read whole file into buffer, without changing read pointer.
117
118           Inputs:
119               0) Reference to RandomAccess object.
120
121           Returns:
122               Nothing.
123
124       BinMode
125           Set binary mode for file.
126
127           Inputs:
128               0) Reference to RandomAccess object.
129
130           Returns:
131               Nothing.
132
133       Close
134           Close the file and free the buffer.
135
136           Inputs:
137               0) Reference to RandomAccess object.
138
139           Returns:
140               Nothing.
141

AUTHOR

143       Copyright 2003-2011 Phil Harvey (phil at owl.phy.queensu.ca)
144
145       This library is free software; you can redistribute it and/or modify it
146       under the same terms as Perl itself.
147

SEE ALSO

149       Image::ExifTool(3pm)
150
151
152
153perl v5.12.4                      2011-01-03             File::RandomAccess(3)
Impressum