firebase-import
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -6,3 +6,5 @@ #!/usr/bin/env node | ||
assert = require('assert'), | ||
path = require('path'); | ||
path = require('path'), | ||
fs = require('fs'), | ||
JSONStream = require('JSONStream'), | ||
util = require('util'); | ||
@@ -84,25 +86,75 @@ | ||
function readFirstNonWhitespaceChar(file, callback) { | ||
var firstChar; | ||
var rs = fs.createReadStream(file); | ||
rs.on('data', function(chunk) { | ||
var s = chunk.toString().trim(); | ||
if (s !== "") { | ||
rs.close(); | ||
} | ||
firstChar = s[0]; | ||
}) | ||
.on('error', callback) | ||
.on('close', function() { | ||
return callback(null, firstChar); | ||
}); | ||
} | ||
function getJsonFromFile(file, callback) { | ||
readFirstNonWhitespaceChar(file, function(err, firstChar) { | ||
var json; | ||
if (firstChar === "[" || firstChar === "{") { | ||
var jsonStream; | ||
var onFunc; | ||
if (firstChar === "[") { | ||
json = []; | ||
jsonStream = JSONStream.parse("*"); | ||
onFunc = function(r) { | ||
json.push(r); | ||
}; | ||
} else { | ||
json = {}; | ||
jsonStream = JSONStream.parse("$*"); | ||
onFunc = function(r) { | ||
json[r.key] = r.value; | ||
}; | ||
} | ||
fs.createReadStream(file) | ||
.pipe(jsonStream) | ||
.on('data', onFunc) | ||
.on('error', callback) | ||
.on('close', function() { | ||
return callback(null, json); | ||
}); | ||
} else { | ||
json = require(file); | ||
return callback(null, json); | ||
} | ||
}); | ||
} | ||
function start(ref) { | ||
var file = path.resolve(argv.json); | ||
console.log('Reading ' + file + '... (may take a minute)'); | ||
var json = require(file); | ||
var clearFirst = true, splitTopLevel = false; | ||
if (argv.merge) { | ||
clearFirst = false; | ||
// Need to split into chunks at the top level to ensure we don't overwrite the parent. | ||
splitTopLevel = true; | ||
} | ||
getJsonFromFile(file, function(err, json) { | ||
var clearFirst = true, splitTopLevel = false; | ||
if (argv.merge) { | ||
clearFirst = false; | ||
// Need to split into chunks at the top level to ensure we don't overwrite the parent. | ||
splitTopLevel = true; | ||
} | ||
console.log('Preparing JSON for import... (may take a minute)'); | ||
var chunks = createChunks(ref, json, splitTopLevel); | ||
console.log('Preparing JSON for import... (may take a minute)'); | ||
var chunks = createChunks(ref, json, splitTopLevel); | ||
if (clearFirst) { | ||
ref.remove(function(error) { | ||
if (error) throw(error); | ||
if (clearFirst) { | ||
ref.remove(function(error) { | ||
if (error) throw(error); | ||
uploadChunks(chunks); | ||
}); | ||
} else { | ||
uploadChunks(chunks); | ||
}); | ||
} else { | ||
uploadChunks(chunks); | ||
} | ||
} | ||
}); | ||
} | ||
@@ -109,0 +161,0 @@ |
@@ -1,3 +0,1 @@ | ||
feature - Updated for Firebase 3.x support. | ||
changed - The --firebase_url option was replaced with --database_url and --path. | ||
changed - Instead of using --auth you must use --service_account and provide a service account. | ||
changed - Uses JSONStream to enable reading larger JSON files. |
{ | ||
"name": "firebase-import", | ||
"description": "npm config for Firebase Import", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"dependencies": { | ||
"JSONStream": "^1.2.1", | ||
"firebase": "^3.4.0", | ||
@@ -7,0 +8,0 @@ "optimist": "^0.6.1", |
# Firebase-Import | ||
Firebase-import is a helper utility for importing large JSON files into your [Firebase](https://www.firebase.com/) database. It | ||
breaks the JSON into smaller chunks and uploads them individually through the Firebase API. | ||
Firebase-import is a helper utility for importing large JSON files into your | ||
[Firebase Realtime Database](https://firebase.google.com/docs/database/). It breaks the JSON into smaller | ||
chunks and uploads them individually through the Firebase API. | ||
@@ -5,0 +6,0 @@ To import files bigger than 250MB, use [Firebase Streaming Import](https://github.com/firebase/firebase-streaming-import). |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
11966
250
54
4
2
1
+ AddedJSONStream@^1.2.1
+ AddedJSONStream@1.3.5(transitive)
+ Addedjsonparse@1.3.1(transitive)
+ Addedthrough@2.3.8(transitive)