Flutter Engine
file_loader_fuchsia.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
6 
7 #include <dirent.h>
8 #include <fcntl.h>
9 #include <sys/types.h>
10 
11 #include <cerrno>
12 #include <iostream>
13 #include <memory>
14 #include <utility>
15 
16 #include "tonic/common/macros.h"
21 
22 namespace tonic {
23 
24 const std::string FileLoader::kPathSeparator = "/";
25 const char FileLoader::kFileURLPrefix[] = "file://";
27  sizeof(FileLoader::kFileURLPrefix) - 1;
28 
29 namespace {
30 
31 const size_t kFileSchemeLength = FileLoader::kFileURLPrefixLength - 2;
32 
33 } // namespace
34 
35 std::string FileLoader::SanitizePath(const std::string& url) {
36  return SanitizeURIEscapedCharacters(url);
37 }
38 
39 std::string FileLoader::CanonicalizeFileURL(const std::string& url) {
40  return url.substr(kFileSchemeLength);
41 }
42 
43 bool FileLoader::ReadFileToString(const std::string& path,
44  std::string* result) {
45  if (dirfd_ == -1)
46  return filesystem::ReadFileToString(path, result);
47  const char* cpath = path.c_str();
48  const int offset = (cpath[0] == '/') ? 1 : 0;
49  filesystem::Descriptor fd(openat(dirfd_, &cpath[offset], O_RDONLY));
50  return filesystem::ReadFileDescriptorToString(fd.get(), result);
51 }
52 
53 std::pair<uint8_t*, intptr_t> FileLoader::ReadFileToBytes(
54  const std::string& path) {
55  if (dirfd_ == -1)
56  return filesystem::ReadFileToBytes(path);
57  const char* cpath = path.c_str();
58  const int offset = (cpath[0] == '/') ? 1 : 0;
59  filesystem::Descriptor fd(openat(dirfd_, &cpath[offset], O_RDONLY));
61 }
62 
63 } // namespace tonic
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
std::pair< uint8_t *, intptr_t > ReadFileToBytes(const std::string &path)
Definition: file.cc:94
static const char kFileURLPrefix[]
Definition: file_loader.h:42
bool ReadFileDescriptorToString(int fd, std::string *result)
Definition: file.cc:90
static const std::string kPathSeparator
Definition: file_loader.h:44
static const size_t kFileURLPrefixLength
Definition: file_loader.h:43
std::pair< uint8_t *, intptr_t > ReadFileDescriptorToBytes(int fd)
Definition: file.cc:63
bool ReadFileToString(const std::string &path, std::string *result)
Definition: file.cc:85