private$fileTree <- private$generateTree(private$fileItems)
},
- printFileContent = function(pretty = TRUE)
+ printFileContent = function()
{
- if(pretty)
- private$fileTree$printContent(0)
- else
- print(private$fileItems)
+ private$fileTree$printContent(0)
+ },
+ getFileContent = function()
+ {
+ sapply(private$fileItems, function(file)
+ {
+ file$name
+ })
},
get = function(relativePath)
private = list(
- api = NULL,
fileItems = NULL,
+ api = NULL,
fileTree = NULL,
createSubcollectionTree = function(treeNode)
else
{
if(treeNode$type == "file")
- return(ArvadosFile$new(treeNode$name, treeNode$relativePath, private$api, self))
- else if(treeNode$type == "folder" || treeNode$type == "root")
+ return(ArvadosFile$new(treeNode$name, treeNode$relativePath, treeNode$size, private$api, self))
+ else
return(Subcollection$new(treeNode$name, treeNode$relativePath, NULL))
}
},
- createSubcollectionFromNode = function(treeNode, children)
- {
- subcollection = NULL
- if(treeNode$type == "file")
- subcollection = ArvadosFile$new(treeNode$name, treeNode$relativePath)
- else if(treeNode$type == "folder" || treeNode$type == "root")
- subcollection = Subcollection$new(treeNode$name, treeNode$relativePath, children)
-
- subcollection
- },
-
getCollectionContent = function()
{
#TODO(Fudo): Use proper URL here.
{
treeBranches <- sapply(collectionContent, function(filePath)
{
- splitPath <- unlist(strsplit(filePath, "/", fixed = TRUE))
+ splitPath <- unlist(strsplit(filePath$name, "/", fixed = TRUE))
- pathEndsWithSlash <- substr(filePath, nchar(filePath), nchar(filePath)) == "/"
-
- branch = private$createBranch(splitPath, pathEndsWithSlash)
+ branch = private$createBranch(splitPath, filePath$fileSize)
})
- root <- TreeNode$new("./", "root")
+ root <- TreeNode$new("./", "root", NULL)
root$relativePath = ""
sapply(treeBranches, function(branch)
root
},
- createBranch = function(splitPath, pathEndsWithSlash)
+ createBranch = function(splitPath, fileSize)
{
branch <- NULL
lastElementIndex <- length(splitPath)
-
- lastElementInPathType = "file"
- if(pathEndsWithSlash)
- lastElementInPathType = "folder"
for(elementIndex in lastElementIndex:1)
{
if(elementIndex == lastElementIndex)
{
- branch = TreeNode$new(splitPath[[elementIndex]], lastElementInPathType)
+ branch = TreeNode$new(splitPath[[elementIndex]], "file", fileSize)
}
else
{
- newFolder = TreeNode$new(splitPath[[elementIndex]], "folder")
+ newFolder = TreeNode$new(splitPath[[elementIndex]], "folder", NULL)
newFolder$addChild(branch)
branch = newFolder
}
branch$relativePath <- paste(unlist(splitPath[1:elementIndex]), collapse = "/")
}
-
+
branch
},
}
else
{
+ child$type = "folder"
private$addNode(child, node$getFirstChild())
}
},
public = list(
- name = NULL,
+ name = NULL,
relativePath = NULL,
- children = NULL,
- parent = NULL,
- type = NULL,
+ size = NULL,
+ children = NULL,
+ parent = NULL,
+ type = NULL,
- initialize = function(name, type)
+ initialize = function(name, type, size)
{
- if(type == "folder")
- name <- paste0(name, "/")
-
self$name <- name
self$type <- type
+ self$size <- size
self$children <- list()
},
printContent = function(depth)
{
indentation <- paste(rep("....", depth), collapse = "")
- print(paste0(indentation, self$name))
+ if(self$type == "folder")
+ print(paste0(indentation, self$name, "/"))
+ else
+ print(paste0(indentation, self$size))
for(child in self$children)
child$printContent(depth + 1)
parseWebDAVResponse = function(response, uri)
{
text <- rawToChar(response$content)
- print(text)
doc <- XML::xmlParse(text, asText=TRUE)
# calculate relative paths
base <- paste(paste("/", strsplit(uri, "/")[[1]][-1:-3], sep="", collapse=""), "/", sep="")
- result <- unlist(
- XML::xpathApply(doc, "//D:response/D:href", function(node) {
- sub(base, "", URLdecode(XML::xmlValue(node)), fixed=TRUE)
- })
- )
- result <- result[result != ""]
+ result <- XML::xpathApply(doc, "//D:response", function(node) {
+ result = list()
+ children = xmlChildren(node)
+
+ result$name = sub(base, "", URLdecode(XML::xmlValue(children$href)), fixed=TRUE)
+ sizeXMLNode = xmlChildren(xmlChildren(children$propstat)$prop)$getcontentlength
+ result$fileSize = as.numeric(xmlValue(sizeXMLNode))
+
+ result
+ })
result[-1]
}
--------------------------------------------------------------------------------------------------------------------------------
-#Print content of the collection
+#Print content of the collection (directory/folder tree structure)
collection$printFileContent()
-#of if you just want a list of relative paths:
+--------------------------------------------------------------------------------------------------------------------------------
+
+#Get file/folder content as character vector
-collection$printFileContent(pretty = FALSE)
+collection$getFileContent()
--------------------------------------------------------------------------------------------------------------------------------
#Read whole file or just a portion of it.
-arvadosFile$read(offset = 1024, length = 512)
+fileContent <- arvadosFile$read(offset = 1024, length = 512)
+
+--------------------------------------------------------------------------------------------------------------------------------
+
+#Get ArvadosFile or Subcollection size
+
+size <- arvadosFile$getSizeInBytes()
+size <- arvadosSubcollection$getSizeInBytes()
--------------------------------------------------------------------------------------------------------------------------------