mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-15 06:35:20 -07:00
Import Buffer directly
This commit is contained in:
parent
4d690b1856
commit
d17ec1c23b
1 changed files with 6 additions and 4 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
// Adpapted for browser+node from https://github.com/joeferner/node-bplist-parser/blob/master/bplistParser.js
|
// Adpapted for browser+node from https://github.com/joeferner/node-bplist-parser/blob/master/bplistParser.js
|
||||||
import plainTextPlist from 'plist'
|
import plainTextPlist from 'plist'
|
||||||
import bigInt from 'big-integer'
|
import bigInt from 'big-integer'
|
||||||
import bufferApi from 'buffer'
|
import { Buffer } from 'buffer/'
|
||||||
|
|
||||||
|
|
||||||
// const fs = require('fs');
|
// const fs = require('fs');
|
||||||
|
|
@ -40,7 +40,7 @@ export function parsePlistBuffer ( fileBuffer , callback) {
|
||||||
|
|
||||||
return tryParseBuffer( fileBuffer )
|
return tryParseBuffer( fileBuffer )
|
||||||
|
|
||||||
// if (bufferApi.Buffer.isBuffer(fileNameOrBuffer)) {
|
// if (Buffer.isBuffer(fileNameOrBuffer)) {
|
||||||
|
|
||||||
// }
|
// }
|
||||||
// fs.readFile(fileNameOrBuffer, function(err, data) {
|
// fs.readFile(fileNameOrBuffer, function(err, data) {
|
||||||
|
|
@ -54,7 +54,7 @@ export function parsePlistBuffer ( fileBuffer , callback) {
|
||||||
};
|
};
|
||||||
|
|
||||||
export function parseFileSync (fileNameOrBuffer) {
|
export function parseFileSync (fileNameOrBuffer) {
|
||||||
// if (!bufferApi.Buffer.isBuffer(fileNameOrBuffer)) {
|
// if (!Buffer.isBuffer(fileNameOrBuffer)) {
|
||||||
// fileNameOrBuffer = fs.readFileSync(fileNameOrBuffer);
|
// fileNameOrBuffer = fs.readFileSync(fileNameOrBuffer);
|
||||||
// }
|
// }
|
||||||
return parseBuffer(fileNameOrBuffer);
|
return parseBuffer(fileNameOrBuffer);
|
||||||
|
|
@ -64,6 +64,8 @@ function parseBuffer ( buffer ) {
|
||||||
// check header
|
// check header
|
||||||
const header = buffer.slice(0, 'bplist'.length).toString('utf8');
|
const header = buffer.slice(0, 'bplist'.length).toString('utf8');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const isPlainTextPlist = header.includes('<?xml')
|
const isPlainTextPlist = header.includes('<?xml')
|
||||||
|
|
||||||
if ( isPlainTextPlist ) {
|
if ( isPlainTextPlist ) {
|
||||||
|
|
@ -276,7 +278,7 @@ function parseBuffer ( buffer ) {
|
||||||
// length is String length -> to get byte length multiply by 2, as 1 character takes 2 bytes in UTF-16
|
// length is String length -> to get byte length multiply by 2, as 1 character takes 2 bytes in UTF-16
|
||||||
length *= (isUtf16 + 1);
|
length *= (isUtf16 + 1);
|
||||||
if (length < maxObjectSize) {
|
if (length < maxObjectSize) {
|
||||||
let plistString = bufferApi.Buffer.from(buffer.slice(offset + stroffset, offset + stroffset + length));
|
let plistString = Buffer.from(buffer.slice(offset + stroffset, offset + stroffset + length));
|
||||||
if (isUtf16) {
|
if (isUtf16) {
|
||||||
plistString = swapBytes(plistString);
|
plistString = swapBytes(plistString);
|
||||||
enc = "ucs2";
|
enc = "ucs2";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue