mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
If $native.read fails to open a file as UTF8, it opens it as ascii
This is a temporary solution to allow Atom to open binary files. The ultimate goal would be to have a hex-editor built into atom.
This commit is contained in:
@@ -50,10 +50,16 @@ bool Native::Execute(const CefString& name,
|
||||
NSString *path = stringFromCefV8Value(arguments[0]);
|
||||
|
||||
NSError *error = nil;
|
||||
NSString *contents = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];
|
||||
NSStringEncoding *encoding = nil;
|
||||
NSString *contents = [NSString stringWithContentsOfFile:path usedEncoding:encoding error:&error];
|
||||
|
||||
NSError *binaryFileError = nil;
|
||||
if (error) {
|
||||
exception = [[error localizedDescription] UTF8String];
|
||||
contents = [NSString stringWithContentsOfFile:path encoding:NSNonLossyASCIIStringEncoding error:&binaryFileError];
|
||||
}
|
||||
|
||||
if (binaryFileError) {
|
||||
exception = [[binaryFileError localizedDescription] UTF8String];
|
||||
}
|
||||
else {
|
||||
retval = CefV8Value::CreateString([contents UTF8String]);
|
||||
|
||||
BIN
spec/fixtures/binary-file.png
vendored
Normal file
BIN
spec/fixtures/binary-file.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 392 B |
@@ -1,6 +1,13 @@
|
||||
fs = require 'fs'
|
||||
|
||||
describe "fs", ->
|
||||
describe ".read(path)", ->
|
||||
it "return contents of file", ->
|
||||
expect(fs.read(require.resolve("fixtures/sample.txt"))).toBe "Some text.\n"
|
||||
|
||||
it "does not through an exception when the path is a binary file", ->
|
||||
expect(-> fs.read(require.resolve("fixtures/binary-file.png"))).not.toThrow()
|
||||
|
||||
describe ".isFile(path)", ->
|
||||
fixturesDir = require.resolve('fixtures')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user