line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geo::GDAL::FFI::VSI::File; |
2
|
5
|
|
|
5
|
|
64
|
use v5.10; |
|
5
|
|
|
|
|
16
|
|
3
|
5
|
|
|
5
|
|
31
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
99
|
|
4
|
5
|
|
|
5
|
|
22
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
168
|
|
5
|
5
|
|
|
5
|
|
28
|
use Encode qw(decode encode); |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
253
|
|
6
|
5
|
|
|
5
|
|
47
|
use Carp; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
257
|
|
7
|
5
|
|
|
5
|
|
31
|
use FFI::Platypus::Buffer; |
|
5
|
|
|
|
|
83
|
|
|
5
|
|
|
|
|
296
|
|
8
|
5
|
|
|
5
|
|
2701
|
use FFI::Platypus::Declare; |
|
5
|
|
|
|
|
6812
|
|
|
5
|
|
|
|
|
35
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = 0.0800; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub Open { |
13
|
0
|
|
|
0
|
1
|
|
my ($class, $path, $access) = @_; |
14
|
0
|
|
0
|
|
|
|
$access //= 'r'; |
15
|
0
|
|
|
|
|
|
my $self = {}; |
16
|
0
|
|
|
|
|
|
$self->{handle} = Geo::GDAL::FFI::VSIFOpenExL(encode(utf8 => $path), $access, 1); |
17
|
0
|
0
|
|
|
|
|
unless ($self->{handle}) { |
18
|
0
|
|
0
|
|
|
|
confess Geo::GDAL::FFI::error_msg() // "Failed to open '$path' with access '$access'."; |
19
|
|
|
|
|
|
|
} |
20
|
0
|
|
|
|
|
|
return bless $self, $class; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub DESTROY { |
24
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
25
|
0
|
|
|
|
|
|
$self->Close; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub Close { |
29
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
30
|
0
|
0
|
|
|
|
|
return unless $self->{handle}; |
31
|
0
|
|
|
|
|
|
my $e = Geo::GDAL::FFI::VSIFCloseL($self->{handle}); |
32
|
0
|
0
|
0
|
|
|
|
confess Geo::GDAL::FFI::error_msg() // "Failed to close a VSIFILE." if $e == -1; |
33
|
0
|
|
|
|
|
|
delete $self->{handle}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub Read { |
37
|
0
|
|
|
0
|
1
|
|
my ($self, $len) = @_; |
38
|
0
|
|
0
|
|
|
|
$len //= 1; |
39
|
0
|
|
|
|
|
|
my $buf = ' ' x $len; |
40
|
0
|
|
|
|
|
|
my ($pointer, $size) = scalar_to_buffer $buf; |
41
|
0
|
|
|
|
|
|
my $n = Geo::GDAL::FFI::VSIFReadL($pointer, 1, $len, $self->{handle}); |
42
|
0
|
|
|
|
|
|
return substr $buf, 0, $n; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub Write { |
46
|
0
|
|
|
0
|
1
|
|
my ($self, $buf) = @_; |
47
|
5
|
|
|
5
|
|
2331
|
my $len = do {use bytes; length($buf)}; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
26
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my $address = cast 'string' => 'opaque', $buf; |
49
|
0
|
|
|
|
|
|
return Geo::GDAL::FFI::VSIFWriteL($address, 1, $len, $self->{handle}); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub Ingest { |
53
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
54
|
0
|
|
|
|
|
|
my $s; |
55
|
0
|
|
|
|
|
|
my $e = Geo::GDAL::FFI::VSIIngestFile($self->{handle}, '', \$s, 0, -1); |
56
|
0
|
|
|
|
|
|
return $s; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=pod |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=encoding UTF-8 |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 NAME |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Geo::GDAL::FFI::VSI::File - A GDAL virtual file |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 SYNOPSIS |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 DESCRIPTION |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 METHODS |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 Open |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my $vsifile = Geo::GDAL::FFI::VSI::File->Open($name, $access); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Open a virtual file. $name is the name of the file to open. $access is |
80
|
|
|
|
|
|
|
'r', 'r+', 'a', or 'w'. 'r' is the default. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Returns a Geo::GDAL::FFI::VSI::File object. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 Close |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Closes the file handle. Is done automatically when the object is |
87
|
|
|
|
|
|
|
destroyed. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 Read($len) |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Read $len bytes from the file. Returns the bytes in a Perl |
92
|
|
|
|
|
|
|
string. $len is optional and by default 1. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 Write($buf) |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Write the Perl string $buf into the file. Returns the number of |
97
|
|
|
|
|
|
|
succesfully written bytes. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 LICENSE |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
This software is released under the Artistic License. See |
102
|
|
|
|
|
|
|
L. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 AUTHOR |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Ari Jolma - Ari.Jolma at gmail.com |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 SEE ALSO |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
L |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
L, L, L |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
__END__; |