{"size": 1430, "ext": "js", "max_stars_repo_path": "bin/benchwrapper.js", "max_stars_repo_name": "praveenqlogic01/nodejs-storage", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "bin/benchwrapper.js", "max_issues_repo_name": "praveenqlogic01/nodejs-storage", "max_issues_repo_issues_event_min_datetime": "2019-08-23T14:35:48.000Z", "max_issues_repo_issues_event_max_datetime": "2019-08-26T19:30:58.000Z", "max_forks_repo_path": "bin/benchwrapper.js", "max_forks_repo_name": "praveenqlogic01/nodejs-storage", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 25.5357142857, "max_line_length": 77, "alphanum_fraction": 0.7062937063}
const grpc = require('grpc');
const protoLoader = require('@grpc/proto-loader');
const {Storage} = require('../build/src');

const argv = require('yargs')
  .option('port', {
    description: 'The port that the Node.js benchwrapper should run on.',
    type: 'number',
    demand: true,
  })
  .parse();

const PROTO_PATH = __dirname + '/storage.proto';
// Suggested options for similarity to existing grpc.load behavior.
const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
  keepCase: true,
  longs: String,
  enums: String,
  defaults: true,
  oneofs: true,
});
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition);
const storageBenchWrapper = protoDescriptor.storage_bench;

const storageClient = new Storage();

function read(call, callback) {
  const bucketName = call.request.bucketName;
  const objectName = call.request.objectName;

  storageClient
    .bucket(bucketName)
    .file(objectName)
    .download({validation: false})
    .then(function(data) {
      // Do nothing with contents.
    });

  callback(null, null);
}

function write(call, callback) {
  // TODO(deklerk)
  callback(null, null);
}

const server = new grpc.Server();

server.addService(storageBenchWrapper['StorageBenchWrapper']['service'], {
  read: read,
  write: write,
});
console.log('starting on localhost:' + argv.port);
server.bind('0.0.0.0:' + argv.port, grpc.ServerCredentials.createInsecure());
server.start();
