Socket
Socket
Sign inDemoInstall

firebase-import

Package Overview
Dependencies
29
Maintainers
3
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0 to 2.1.0

86

bin/firebase-import.js

@@ -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 @@

4

changelog.txt

@@ -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).

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc