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
c1b7a481
Commit
c1b7a481
authored
7 years ago
by
Matthieu Muffato
Browse files
Options
Downloads
Patches
Plain Diff
Added the opposite of slurp: spurt
parent
29c98e98
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!213
Added the opposite of slurp: spurt
,
!213
Added the opposite of slurp: spurt
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/Bio/EnsEMBL/Utils/IO.pm
+30
-1
30 additions, 1 deletion
modules/Bio/EnsEMBL/Utils/IO.pm
modules/t/utilsIo.t
+9
-0
9 additions, 0 deletions
modules/t/utilsIo.t
with
39 additions
and
1 deletion
modules/Bio/EnsEMBL/Utils/IO.pm
+
30
−
1
View file @
c1b7a481
...
...
@@ -131,10 +131,11 @@ our $GZIP_OK = 0;
our
$BZIP2_OK
=
0
;
our
$ZIP_OK
=
0
;
our
@EXPORT_OK
=
qw/slurp slurp_to_array fh_to_array process_to_array work_with_file gz_slurp gz_slurp_to_array gz_work_with_file bz_slurp bz_slurp_to_array bz_work_with_file zip_slurp zip_slurp_to_array zip_work_with_file filter_dir iterate_file iterate_lines move_data/
;
our
@EXPORT_OK
=
qw/slurp slurp_to_array fh_to_array process_to_array work_with_file gz_slurp gz_slurp_to_array gz_work_with_file bz_slurp bz_slurp_to_array bz_work_with_file zip_slurp zip_slurp_to_array zip_work_with_file
spurt
filter_dir iterate_file iterate_lines move_data/
;
our
%EXPORT_TAGS
=
(
all
=>
[
@EXPORT_OK
],
slurp
=>
[
qw/slurp slurp_to_array gz_slurp gz_slurp_to_array/
],
spurt
=>
[
qw/spurt/
],
array
=>
[
qw/fh_to_array process_to_array slurp_to_array gz_slurp_to_array/
],
gz
=>
[
qw/gz_slurp gz_slurp_to_array gz_work_with_file/
],
bz
=>
[
qw/bz_slurp bz_slurp_to_array bz_work_with_file/
],
...
...
@@ -201,6 +202,34 @@ sub slurp {
return
(
$want_ref
)
?
\
$contents
:
$contents
;
}
=head2 spurt()
Arg [1] : string $file
Arg [2] : string $contents
Arg [3] : boolean; $append
Arg [4] : boolean; $binary
Description : Convenient method to safely open a file and dump some content into it.
$append can be set to append to the file instead of resetting it first.
$binary can be set if the content you are printing is not plain-text.
Returntype : None
Example : spurt('/tmp/file.txt', $contents);
Exceptions : If the file could not be created or was not writable
Status : Stable
=cut
sub
spurt
{
my
(
$file
,
$contents
,
$append
,
$binary
)
=
@_
;
work_with_file
(
$file
,
$append
?
'
a
'
:
'
w
',
sub
{
my
(
$fh
)
=
@_
;
binmode
(
$fh
)
if
$binary
;
syswrite
(
$fh
,
$contents
);
}
);
}
=head2 gz_slurp
Arg [1] : string $file
...
...
This diff is collapsed.
Click to expand it.
modules/t/utilsIo.t
+
9
−
0
View file @
c1b7a481
...
...
@@ -77,6 +77,15 @@ my $expected_array = [qw/>X AAAAGGGTTCCC TTGGCCAAAAAA ATTC/];
dies_ok
{
slurp
(
$file
)
}
'
File no longer exists so die
';
spurt
(
$file
,
$contents
);
my
$rewritten_contents
=
slurp
(
$file
);
is
(
$contents
,
$rewritten_contents
,
'
Contents should still be the same
');
spurt
(
$file
,
$contents
,
'
append
');
$rewritten_contents
=
slurp
(
$file
);
is
(
$contents
.
$contents
,
$rewritten_contents
,
'
Contents should be doubled
');
unlink
$file
;
}
{
...
...
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