Skip to content

Commit

Permalink
Merge pull request #159 from jsams/rdata_single
Browse files Browse the repository at this point in the history
Add support for Rdata single format (.rds files)
  • Loading branch information
timholy authored Nov 27, 2017
2 parents c3e1ee7 + 7a8b810 commit 4bf7c2e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/registry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ end

add_format(format"RData", detect_rdata, [".rda", ".RData", ".rdata"], [:RData, LOAD])

function detect_rdata_single(io)
seekstart(io)
res = read(io, UInt8) in (UInt8('A'), UInt8('B'), UInt8('X')) &&
(c = read(io, UInt8); c == UInt8('\n') || (c == UInt8('\r') && read(io, UInt8) == UInt8('\n')))
seekstart(io)
return res
end

add_format(format"RDataSingle", detect_rdata_single, [".rds"], [:RData, LOAD])

add_format(format"CSV", (), [".csv"], [:CSVFiles])
add_format(format"TSV", (), [".tsv"], [:CSVFiles])
add_format(format"Feather", "FEA1", [".feather"], [:FeatherFiles])
Expand Down
40 changes: 40 additions & 0 deletions test/files/minimal_ascii.rds
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
A
2
197634
131840
787
1
14
2
1.1
2.2
1026
1
262153
5
names
16
1
262153
3
num
1026
1
262153
9
row.names
13
2
NA
-2
1026
1
262153
5
class
16
1
262153
10
data.frame
254
10 changes: 10 additions & 0 deletions test/query.jl
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,16 @@ end
@test (position(io) in (5, 6))
end
end
@testset "RDS detection" begin
q = query(joinpath(file_dir, "minimal_ascii.rds"))
@test typeof(q) == File{format"RDataSingle"}
open(q) do io
@test position(io) == 0
@test FileIO.detect_rdata_single(io)
# need to seek to beginning of file where data structure starts
@test position(io) == 0
end
end
@testset "Format with function for magic bytes" begin
add_format(format"FUNCTION_FOR_MAGIC_BYTES", x -> 0x00, ".wav", [:WAV])
del_format(format"FUNCTION_FOR_MAGIC_BYTES")
Expand Down

0 comments on commit 4bf7c2e

Please sign in to comment.