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 | |
5 | #include "tonic/file_loader/file_loader.h" |
6 | |
7 | #include <iostream> |
8 | #include <memory> |
9 | #include <utility> |
10 | |
11 | #include "filesystem/file.h" |
12 | #include "filesystem/path.h" |
13 | #include "tonic/common/macros.h" |
14 | #include "tonic/converter/dart_converter.h" |
15 | #include "tonic/parsers/packages_map.h" |
16 | |
17 | namespace tonic { |
18 | |
19 | const std::string FileLoader::kPathSeparator = "/"; |
20 | const char FileLoader::kFileURLPrefix[] = "file://"; |
21 | const size_t FileLoader::kFileURLPrefixLength = |
22 | sizeof(FileLoader::kFileURLPrefix) - 1; |
23 | |
24 | namespace { |
25 | |
26 | const size_t kFileSchemeLength = FileLoader::kFileURLPrefixLength - 2; |
27 | |
28 | } // namespace |
29 | |
30 | std::string FileLoader::SanitizePath(const std::string& url) { |
31 | return SanitizeURIEscapedCharacters(url); |
32 | } |
33 | |
34 | std::string FileLoader::CanonicalizeFileURL(const std::string& url) { |
35 | return url.substr(kFileSchemeLength); |
36 | } |
37 | |
38 | bool FileLoader::ReadFileToString(const std::string& path, |
39 | std::string* result) { |
40 | TONIC_DCHECK(dirfd_ == -1); |
41 | return filesystem::ReadFileToString(path, result); |
42 | } |
43 | |
44 | std::pair<uint8_t*, intptr_t> FileLoader::ReadFileToBytes( |
45 | const std::string& path) { |
46 | TONIC_DCHECK(dirfd_ == -1); |
47 | return filesystem::ReadFileToBytes(path); |
48 | } |
49 | |
50 | } // namespace tonic |
51 |