-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paths3-part.r
62 lines (50 loc) · 1.47 KB
/
s3-part.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
library(aws.s3)
source("part-api.r")
init_s3_part <- function(bucket_name) {
options(default_part_constructor=as_s3_part)
options(s3_bucket_name=bucket_name)
invisible(TRUE)
}
# This should be changed so parts can be stored at different urls.
as_s3_part <- function(x, ...) {
ret <- list(bucket_name=options()$s3_bucket_name, file_name=guid())
class(ret) <- c(class(ret), "s3.part")
put_object(serialize(x, NULL), ret$file_name, ret$bucket_name, ...)
ret
}
s3_retrieve <- function(file_name, bucket_name, ...) {
unserialize(get_object(file_name, bucket_name, ...))
}
get_values.s3.part <- function(part, i, ...) {
# TODO: add other relevant parameters.
x <- s3_retrieve(part$file_name, part$bucket_name)
if (!missing(i) && !missing(...)) {
x[i, ...]
} else if (missing(i) && !missing(...)) {
x[...]
} else if (!missing(i) && missing(...)) {
x[i]
} else {
x
}
}
get_attributes.s3.part <- function(part, labels) {
x <- s3_retrieve(part$file_name, part$bucket_name)
if (missing(labels)) {
attributes(x)
} else {
attributes(x)[[labels]]
}
}
get_object_size.s3.part <- function(part) {
object.size(s3_retrieve(part$file_name, part$bucket_name))
}
get_typeof.s3.part <- function(part) {
typeof(s3_retrieve(part$file_name, part$bucket_name))
}
get_class.s3.part <- function(part) {
class(s3_retrieve(part$file_name, part$bucket_name))
}
delete_part.s3.part <- function(part) {
delete_object(part$file_name, part$bucket_name)
}