1 | #------------------------------------------------------------------------------
|
---|
2 | # File: RandomAccess.pod -- Documentation for File::RandomAccess
|
---|
3 | #
|
---|
4 | # Description: Buffer to support random access reading of sequential file
|
---|
5 | #
|
---|
6 | # Legal: Copyright (c) 2004-2006 Phil Harvey (phil at owl.phy.queensu.ca)
|
---|
7 | # This library is free software; you can redistribute it and/or
|
---|
8 | # modify it under the same terms as Perl itself.
|
---|
9 | #------------------------------------------------------------------------------
|
---|
10 |
|
---|
11 | =head1 NAME
|
---|
12 |
|
---|
13 | File::RandomAccess - Random access reads of sequential file or scalar
|
---|
14 |
|
---|
15 | =head1 SYNOPSIS
|
---|
16 |
|
---|
17 | use File::RandomAccess;
|
---|
18 |
|
---|
19 | $raf = new File::RandomAccess(\*FILE, $disableSeekTest);
|
---|
20 |
|
---|
21 | $raf = new File::RandomAccess(\$data);
|
---|
22 |
|
---|
23 | $err = $raf->Seek($pos);
|
---|
24 | $num = $raf->Read($buff, $bytes);
|
---|
25 |
|
---|
26 | =head1 DESCRIPTION
|
---|
27 |
|
---|
28 | Allows random access to sequential file by buffering the file if necessary.
|
---|
29 | Also allows access to data in memory to be accessed as if it were a file.
|
---|
30 |
|
---|
31 | =head1 METHODS
|
---|
32 |
|
---|
33 | =over 4
|
---|
34 |
|
---|
35 | =item B<new>
|
---|
36 |
|
---|
37 | Creates a new RandomAccess object given a file reference or
|
---|
38 | reference to data in memory.
|
---|
39 |
|
---|
40 | # Read from open file or pipe
|
---|
41 | $raf = new File::RandomAccess(\*FILE);
|
---|
42 |
|
---|
43 | # Read from data in memory
|
---|
44 | $raf = new File::RandomAccess(\$data);
|
---|
45 |
|
---|
46 | =over 4
|
---|
47 |
|
---|
48 | =item Inputs:
|
---|
49 |
|
---|
50 | 0) Reference to RandomAccess object.
|
---|
51 |
|
---|
52 | 1) File reference or scalar reference.
|
---|
53 |
|
---|
54 | 2) flag set if file is already random access (disables automatic SeekTest).
|
---|
55 |
|
---|
56 | =item Returns:
|
---|
57 |
|
---|
58 | Reference to RandomAccess object.
|
---|
59 |
|
---|
60 | =back
|
---|
61 |
|
---|
62 | =item B<SeekTest>
|
---|
63 |
|
---|
64 | Performs test seek() on file to determine if buffering is necessary. If
|
---|
65 | the seek() fails, then the file is buffered to allow random access.
|
---|
66 | B<SeekTest>() is automatically called from B<new> unless specified.
|
---|
67 |
|
---|
68 | $result = $raf->SeekTest();
|
---|
69 |
|
---|
70 | =over 4
|
---|
71 |
|
---|
72 | =item Inputs:
|
---|
73 |
|
---|
74 | 0) Reference to RandomAccess object.
|
---|
75 |
|
---|
76 | =item Returns:
|
---|
77 |
|
---|
78 | 1 if seek test passed (ie. no buffering required).
|
---|
79 |
|
---|
80 | =item Notes:
|
---|
81 |
|
---|
82 | Must be called before any other i/o.
|
---|
83 |
|
---|
84 | =back
|
---|
85 |
|
---|
86 | =item B<Tell>
|
---|
87 |
|
---|
88 | Get current position in file
|
---|
89 |
|
---|
90 | $pos = $raf->Tell();
|
---|
91 |
|
---|
92 | =over 4
|
---|
93 |
|
---|
94 | =item Inputs:
|
---|
95 |
|
---|
96 | 0) Reference to RandomAccess object.
|
---|
97 |
|
---|
98 | =item Returns:
|
---|
99 |
|
---|
100 | Current position in file
|
---|
101 |
|
---|
102 | =back
|
---|
103 |
|
---|
104 | =item B<Seek>
|
---|
105 |
|
---|
106 | Seek to specified position in file. When buffered, this doesn't quite
|
---|
107 | behave like seek() since it returns success even if you seek outside the
|
---|
108 | limits of the file.
|
---|
109 |
|
---|
110 | $success = $raf->Seek($pos, 0);
|
---|
111 |
|
---|
112 | =over 4
|
---|
113 |
|
---|
114 | =item Inputs:
|
---|
115 |
|
---|
116 | 0) Reference to RandomAccess object.
|
---|
117 |
|
---|
118 | 1) Position.
|
---|
119 |
|
---|
120 | 2) Whence (0=from start, 1=from cur pos, 2=from end).
|
---|
121 |
|
---|
122 | =item Returns:
|
---|
123 |
|
---|
124 | 1 on success, 0 otherwise
|
---|
125 |
|
---|
126 | =back
|
---|
127 |
|
---|
128 | =item B<Read>
|
---|
129 |
|
---|
130 | Read data from the file.
|
---|
131 |
|
---|
132 | $num = $raf->Read($buff, 1024);
|
---|
133 |
|
---|
134 | =over 4
|
---|
135 |
|
---|
136 | =item Inputs:
|
---|
137 |
|
---|
138 | 0) Reference to RandomAccess object.
|
---|
139 |
|
---|
140 | 1) Buffer.
|
---|
141 |
|
---|
142 | 2) Number of bytes to read.
|
---|
143 |
|
---|
144 | =item Returns:
|
---|
145 |
|
---|
146 | Number of bytes actually read.
|
---|
147 |
|
---|
148 | =back
|
---|
149 |
|
---|
150 | =item B<ReadLine>
|
---|
151 |
|
---|
152 | Read a line from file (end of line is $/).
|
---|
153 |
|
---|
154 | =over 4
|
---|
155 |
|
---|
156 | =item Inputs:
|
---|
157 |
|
---|
158 | 0) Reference to RandomAccess object.
|
---|
159 |
|
---|
160 | 1) Buffer.
|
---|
161 |
|
---|
162 | =item Returns:
|
---|
163 |
|
---|
164 | Number of bytes read.
|
---|
165 |
|
---|
166 | =back
|
---|
167 |
|
---|
168 | =item B<Slurp>
|
---|
169 |
|
---|
170 | Read whole file into buffer, without changing read pointer.
|
---|
171 |
|
---|
172 | =over 4
|
---|
173 |
|
---|
174 | =item Inputs:
|
---|
175 |
|
---|
176 | 0) Reference to RandomAccess object.
|
---|
177 |
|
---|
178 | =item Returns:
|
---|
179 |
|
---|
180 | Nothing.
|
---|
181 |
|
---|
182 | =back
|
---|
183 |
|
---|
184 | =item B<BinMode>
|
---|
185 |
|
---|
186 | Set binary mode for file.
|
---|
187 |
|
---|
188 | =over 4
|
---|
189 |
|
---|
190 | =item Inputs:
|
---|
191 |
|
---|
192 | 0) Reference to RandomAccess object.
|
---|
193 |
|
---|
194 | =item Returns:
|
---|
195 |
|
---|
196 | Nothing.
|
---|
197 |
|
---|
198 | =back
|
---|
199 |
|
---|
200 | =item B<Close>
|
---|
201 |
|
---|
202 | Close the file and free the buffer.
|
---|
203 |
|
---|
204 | =over 4
|
---|
205 |
|
---|
206 | =item Inputs:
|
---|
207 |
|
---|
208 | 0) Reference to RandomAccess object.
|
---|
209 |
|
---|
210 | =item Returns:
|
---|
211 |
|
---|
212 | Nothing.
|
---|
213 |
|
---|
214 | =back
|
---|
215 |
|
---|
216 | =back
|
---|
217 |
|
---|
218 | =head1 AUTHOR
|
---|
219 |
|
---|
220 | Copyright 2004-2006 Phil Harvey (phil at owl.phy.queensu.ca)
|
---|
221 |
|
---|
222 | This library is free software; you can redistribute it and/or modify it
|
---|
223 | under the same terms as Perl itself.
|
---|
224 |
|
---|
225 | =head1 SEE ALSO
|
---|
226 |
|
---|
227 | L<Image::ExifTool(3pm)|Image::ExifTool>
|
---|
228 |
|
---|
229 | =cut
|
---|
230 |
|
---|
231 | # end
|
---|