source: gs2-extensions/parallel-building/trunk/src/perllib/cpan/File/RandomAccess.pod@ 24626

Last change on this file since 24626 was 24626, checked in by jmt12, 13 years ago

An (almost) complete copy of the perllib directory from a (circa SEP2011) head checkout from Greenstone 2 trunk - in order to try and make merging in this extension a little easier later on (as there have been some major changes to buildcol.pl commited in the main trunk but not in the x64 branch)

File size: 3.6 KB
Line 
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) 2003-2010 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
13File::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
28Allows random access to sequential file by buffering the file if necessary.
29Also 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
37Creates a new RandomAccess object given a file reference or
38reference 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
500) Reference to RandomAccess object.
51
521) File reference or scalar reference.
53
542) flag set if file is already random access (disables automatic SeekTest).
55
56=item Returns:
57
58Reference to RandomAccess object.
59
60=back
61
62=item B<SeekTest>
63
64Performs test seek() on file to determine if buffering is necessary. If
65the seek() fails, then the file is buffered to allow random access.
66B<SeekTest>() is automatically called from B<new> unless specified.
67
68 $result = $raf->SeekTest();
69
70=over 4
71
72=item Inputs:
73
740) Reference to RandomAccess object.
75
76=item Returns:
77
781 if seek test passed (ie. no buffering required).
79
80=item Notes:
81
82Must be called before any other i/o.
83
84=back
85
86=item B<Tell>
87
88Get current position in file
89
90 $pos = $raf->Tell();
91
92=over 4
93
94=item Inputs:
95
960) Reference to RandomAccess object.
97
98=item Returns:
99
100Current position in file
101
102=back
103
104=item B<Seek>
105
106Seek to specified position in file. When buffered, this doesn't quite
107behave like seek() since it returns success even if you seek outside the
108limits of the file.
109
110 $success = $raf->Seek($pos, 0);
111
112=over 4
113
114=item Inputs:
115
1160) Reference to RandomAccess object.
117
1181) Position.
119
1202) Whence (0=from start, 1=from cur pos, 2=from end).
121
122=item Returns:
123
1241 on success, 0 otherwise
125
126=back
127
128=item B<Read>
129
130Read data from the file.
131
132 $num = $raf->Read($buff, 1024);
133
134=over 4
135
136=item Inputs:
137
1380) Reference to RandomAccess object.
139
1401) Buffer.
141
1422) Number of bytes to read.
143
144=item Returns:
145
146Number of bytes actually read.
147
148=back
149
150=item B<ReadLine>
151
152Read a line from file (end of line is $/).
153
154=over 4
155
156=item Inputs:
157
1580) Reference to RandomAccess object.
159
1601) Buffer.
161
162=item Returns:
163
164Number of bytes read.
165
166=back
167
168=item B<Slurp>
169
170Read whole file into buffer, without changing read pointer.
171
172=over 4
173
174=item Inputs:
175
1760) Reference to RandomAccess object.
177
178=item Returns:
179
180Nothing.
181
182=back
183
184=item B<BinMode>
185
186Set binary mode for file.
187
188=over 4
189
190=item Inputs:
191
1920) Reference to RandomAccess object.
193
194=item Returns:
195
196Nothing.
197
198=back
199
200=item B<Close>
201
202Close the file and free the buffer.
203
204=over 4
205
206=item Inputs:
207
2080) Reference to RandomAccess object.
209
210=item Returns:
211
212Nothing.
213
214=back
215
216=back
217
218=head1 AUTHOR
219
220Copyright 2003-2011 Phil Harvey (phil at owl.phy.queensu.ca)
221
222This library is free software; you can redistribute it and/or modify it
223under the same terms as Perl itself.
224
225=head1 SEE ALSO
226
227L<Image::ExifTool(3pm)|Image::ExifTool>
228
229=cut
230
231# end
Note: See TracBrowser for help on using the repository browser.