-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
68 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,102 @@ | ||
var bplistParser = require('bplist-parser'), | ||
bplistCreator = require('bplist-creator'), | ||
plist = require('plist'), | ||
fs = require('fs'); | ||
bplistCreator = require('bplist-creator'), | ||
plist = require('plist'), | ||
fs = require('fs'); | ||
|
||
// reveal the underlying modules | ||
exports.plist = plist; | ||
exports.bplistCreator = bplistCreator; | ||
exports.bplistParser = bplistParser; | ||
|
||
|
||
// Parses the given file and returns its contents as a native JavaScript object. | ||
// Parses the given file and returns its contents as a native JavaScript | ||
// object. | ||
exports.readFileSync = function(aFile) { | ||
var contents = fs.readFileSync(aFile); | ||
var contents = fs.readFileSync(aFile); | ||
|
||
if (contents.length === 0) { | ||
console.error("Unable to read file '%s'", aFile); | ||
return {}; | ||
} | ||
return exports.parse(contents, aFile); | ||
if (contents.length === 0) { | ||
console.error("Unable to read file '%s'", aFile); | ||
return {}; | ||
} | ||
return exports.parse(contents, aFile); | ||
}; | ||
|
||
exports.readFile = function(aFile, callback) { | ||
var results; | ||
|
||
fs.readFile(aFile, function(err, contents){ | ||
if (err) { | ||
callback(err); | ||
} | ||
else { | ||
|
||
try { | ||
results = exports.parse(contents, aFile); | ||
callback(null,results); | ||
} | ||
catch(err) { | ||
callback(err); | ||
} | ||
|
||
} | ||
}); | ||
var results; | ||
|
||
fs.readFile(aFile, function(err, contents){ | ||
if (err) { | ||
callback(err); | ||
} | ||
else { | ||
try { | ||
results = exports.parse(contents, aFile); | ||
callback(null,results); | ||
} | ||
catch(err) { | ||
callback(err); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
exports.writeFileSync = function(aFile, anObject, options) { | ||
var data = plist.build(anObject); | ||
fs.writeFileSync(aFile, data, options); | ||
var data = plist.build(anObject); | ||
fs.writeFileSync(aFile, data, options); | ||
}; | ||
|
||
exports.writeFile = function(aFile, anObject, options, callback) { | ||
if (arguments.length === 3 && typeof options === 'function') { | ||
callback = options; | ||
options = undefined; | ||
} | ||
var data = plist.build(anObject); | ||
fs.writeFile(aFile, data, options, callback); | ||
if (arguments.length === 3 && typeof options === 'function') { | ||
callback = options; | ||
options = undefined; | ||
} | ||
var data = plist.build(anObject); | ||
fs.writeFile(aFile, data, options, callback); | ||
}; | ||
|
||
exports.writeBinaryFileSync = function(aFile, anObject, options) { | ||
var data = bplistCreator(anObject); | ||
fs.writeFileSync(aFile, data, options); | ||
var data = bplistCreator(anObject); | ||
fs.writeFileSync(aFile, data, options); | ||
}; | ||
|
||
exports.writeBinaryFile = function(aFile, anObject, options, callback) { | ||
if (arguments.length === 3 && typeof options === 'function') { | ||
callback = options; | ||
options = undefined; | ||
} | ||
if (arguments.length === 3 && typeof options === 'function') { | ||
callback = options; | ||
options = undefined; | ||
} | ||
|
||
var data = bplistCreator(anObject); | ||
fs.writeFile(aFile, data, options, callback); | ||
var data = bplistCreator(anObject); | ||
fs.writeFile(aFile, data, options, callback); | ||
}; | ||
|
||
exports.stringify = function(anObject) { | ||
return plist.build(anObject); | ||
return plist.build(anObject); | ||
}; | ||
|
||
|
||
|
||
exports.parse = function(aStringOrBuffer, aFile) { | ||
var results, | ||
firstByte = aStringOrBuffer[0]; | ||
try { | ||
if (firstByte === 60 || firstByte === '<') { | ||
results = plist.parse(aStringOrBuffer.toString()); | ||
} | ||
else if (firstByte === 98) { | ||
results = bplistParser.parseBuffer(aStringOrBuffer)[0]; | ||
} | ||
else { | ||
if (aFile != undefined) { | ||
console.error("Unable to determine format for '%s'", aFile); | ||
} | ||
else { | ||
console.error("Unable to determine format for plist aStringOrBuffer: '%s'", aStringOrBuffer); | ||
} | ||
results = {}; | ||
} | ||
} | ||
catch(e) { | ||
throw Error("'%s' has errors", aFile); | ||
} | ||
return results; | ||
var results, | ||
firstByte = aStringOrBuffer[0]; | ||
try { | ||
if (firstByte === 60 || firstByte === '<') { | ||
results = plist.parse(aStringOrBuffer.toString()); | ||
} | ||
else if (firstByte === 98) { | ||
results = bplistParser.parseBuffer(aStringOrBuffer)[0]; | ||
} | ||
else { | ||
if (aFile != undefined) { | ||
console.error("Unable to determine format for '%s'", aFile); | ||
} | ||
else { | ||
console.error("Unable to determine format for plist aStringOrBuffer: '%s'", aStringOrBuffer); | ||
} | ||
results = {}; | ||
} | ||
} | ||
catch(e) { | ||
throw Error("'%s' has errors", aFile); | ||
} | ||
return results; | ||
} |