@@ -100,6 +100,9 @@ pub trait FileLoader {
100
100
101
101
/// Read the contents of a UTF-8 file into memory.
102
102
fn read_file ( & self , path : & Path ) -> io:: Result < String > ;
103
+
104
+ /// Read the contents of a potentially non-UTF-8 file into memory.
105
+ fn read_binary_file ( & self , path : & Path ) -> io:: Result < Vec < u8 > > ;
103
106
}
104
107
105
108
/// A FileLoader that uses std::fs to load real files.
@@ -113,6 +116,10 @@ impl FileLoader for RealFileLoader {
113
116
fn read_file ( & self , path : & Path ) -> io:: Result < String > {
114
117
fs:: read_to_string ( path)
115
118
}
119
+
120
+ fn read_binary_file ( & self , path : & Path ) -> io:: Result < Vec < u8 > > {
121
+ fs:: read ( path)
122
+ }
116
123
}
117
124
118
125
/// This is a [SourceFile] identifier that is used to correlate source files between
@@ -220,9 +227,7 @@ impl SourceMap {
220
227
/// Unlike `load_file`, guarantees that no normalization like BOM-removal
221
228
/// takes place.
222
229
pub fn load_binary_file ( & self , path : & Path ) -> io:: Result < Vec < u8 > > {
223
- // Ideally, this should use `self.file_loader`, but it can't
224
- // deal with binary files yet.
225
- let bytes = fs:: read ( path) ?;
230
+ let bytes = self . file_loader . read_binary_file ( path) ?;
226
231
227
232
// We need to add file to the `SourceMap`, so that it is present
228
233
// in dep-info. There's also an edge case that file might be both
0 commit comments