Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ensembl
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ensembl-gh-mirror
ensembl
Commits
1c20e6a2
Commit
1c20e6a2
authored
10 years ago
by
Alessandro Vullo
Browse files
Options
Downloads
Patches
Plain Diff
bzip2 based array slurping and corresponding tests.
parent
9ea373a2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/Bio/EnsEMBL/Utils/IO.pm
+27
-3
27 additions, 3 deletions
modules/Bio/EnsEMBL/Utils/IO.pm
modules/t/io.t
+9
-2
9 additions, 2 deletions
modules/t/io.t
with
36 additions
and
5 deletions
modules/Bio/EnsEMBL/Utils/IO.pm
+
27
−
3
View file @
1c20e6a2
...
...
@@ -317,14 +317,14 @@ sub slurp_to_array {
return
$contents
;
}
=head2 gz_slurp_to_array
()
=head2 gz_slurp_to_array
Arg [1] : string $file
Arg [2] : boolean $chomp
Arg [3] : HashRef arguments to pass into IO compression layers
Description : Sends the contents of the given gzipped file into an ArrayRef
Returntype : ArrayRef
Example : my $contents_array = slurp_to_array('/tmp/file.txt.gz');
Example : my $contents_array =
gz_
slurp_to_array('/tmp/file.txt.gz');
Exceptions : If the file did not exist or was not readable
Status : Stable
...
...
@@ -341,7 +341,31 @@ sub gz_slurp_to_array {
return
$contents
;
}
=head2 fh_to_array()
=head2 bz_slurp_to_array
Arg [1] : string $file
Arg [2] : boolean $chomp
Arg [3] : HashRef arguments to pass into IO compression layers
Description : Sends the contents of the given bzipped file into an ArrayRef
Returntype : ArrayRef
Example : my $contents_array = bz_slurp_to_array('/tmp/file.txt.bz2');
Exceptions : If the file did not exist or was not readable
Status : Stable
=cut
sub
bz_slurp_to_array
{
my
(
$file
,
$chomp
,
$args
)
=
@_
;
my
$contents
;
bz_work_with_file
(
$file
,
'
r
',
sub
{
my
(
$fh
)
=
@_
;
$contents
=
fh_to_array
(
$fh
,
$chomp
);
return
;
},
$args
);
return
$contents
;
}
=head2 fh_to_array
Arg [1] : Glob/IO::Handle $fh
Arg [2] : boolean $chomp
...
...
This diff is collapsed.
Click to expand it.
modules/t/io.t
+
9
−
2
View file @
1c20e6a2
...
...
@@ -69,6 +69,12 @@ SKIP: {
my
$content
=
bz_slurp
(
$bz2tmpfile
->
filename
);
like
(
$content
,
qr/test data/
,
"
Bzip2: correct content
");
like
(
$content
,
qr/more data/
,
"
Bzip2: more correct content
");
# test bz_slurp_to_array
my
$content_array
=
bz_slurp_to_array
(
$bz2tmpfile
->
filename
,
1
);
ok
(
$content_array
->
[
0
]
eq
'
test data
',
"
Bzip2 slurped file first element
");
ok
(
$content_array
->
[
1
]
eq
'
some more data.
',
"
Bzip2 slurped file second element
");
}
my
$ZIP_OK
=
0
;
...
...
@@ -80,12 +86,12 @@ eval {
SKIP:
{
skip
"
Cannot run Zip/Unzip tests, install related IO::[Un]Compress modules first
",
2
unless
$
B
ZIP
2
_OK
;
2
unless
$ZIP_OK
;
# send the content of the tmpfile to another
# bzip2 compressed file
my
$file_content
=
slurp
(
$tmpfilename
);
my
$bz2tmpfile
=
File::
Temp
->
new
(
DIR
=>
$dirname
,
SUFFIX
=>
'
.
bz2
');
my
$bz2tmpfile
=
File::
Temp
->
new
(
DIR
=>
$dirname
,
SUFFIX
=>
'
.
zip
');
zip_work_with_file
(
$bz2tmpfile
->
filename
,
'
w
',
sub
{
my
(
$fh
)
=
@_
;
...
...
@@ -97,6 +103,7 @@ SKIP: {
my
$content
=
zip_slurp
(
$bz2tmpfile
->
filename
);
like
(
$content
,
qr/test data/
,
"
Zip: correct content
");
like
(
$content
,
qr/more data/
,
"
Zip: more correct content
");
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment