bsondump

package
v0.0.0-...-34ebdd2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package bsondump converts BSON files into human-readable formats such as JSON.

Index

Constants

View Source
const (
	DebugOutputType = "debug"
	JSONOutputType  = "json"
)

Types out output supported by the --type option

Variables

View Source
var Usage = `<options> <file>

View and debug .bson files.

See http://docs.mongodb.com/database-tools/bsondump/ for more information.`

Functions

This section is empty.

Types

type BSONDump

type BSONDump struct {
	// generic mongo tool options
	ToolOptions *options.ToolOptions

	// OutputOptions defines options used to control how BSON data is displayed
	OutputOptions *OutputOptions

	// File handle for the output data.
	OutputWriter io.WriteCloser

	InputSource *db.BSONSource
}

BSONDump is a container for the user-specified options and internal state used for running bsondump.

func New

func New(opts Options) (*BSONDump, error)

New constructs a new instance of BSONDump configured by the provided options. A successfully created instance must be closed with Close().

func (*BSONDump) Close

func (bd *BSONDump) Close() error

Close cleans up the internal state of the given BSONDump instance. The instance should not be used again after Close is called.

func (*BSONDump) Debug

func (bd *BSONDump) Debug() (int, error)

Debug iterates through the BSON file and for each document it finds, recursively descends into objects and arrays and prints a human readable BSON representation containing the type and size of each field. It returns the number of documents processed and a non-nil error if one is encountered before the end of the file is reached.

func (*BSONDump) JSON

func (bd *BSONDump) JSON() (int, error)

JSON iterates through the BSON file and for each document it finds, recursively descends into objects and arrays and prints the human readable JSON representation. It returns the number of documents processed and a non-nil error if one is encountered before the end of the file is reached.

type Options

type Options struct {
	*options.ToolOptions
	*OutputOptions
}

Options contains all the possible options used to configure bsondump.

func ParseOptions

func ParseOptions(rawArgs []string, versionStr, gitCommit string) (Options, error)

ParseOptions translates the command line arguments into an Options used to configure BSONDump.

type OutputOptions

type OutputOptions struct {
	// Format to display the BSON data file
	Type string `long:"type" value-name:"<type>" default:"json" default-mask:"-" description:"type of output: debug, json"`

	// Validate each BSON document before displaying
	ObjCheck bool `long:"objcheck" description:"validate BSON during processing"`

	// Display JSON data with indents
	Pretty bool `long:"pretty" description:"output JSON formatted to be human-readable"`

	// Path to input BSON file
	BSONFileName string `long:"bsonFile" description:"path to BSON file to dump to JSON; default is stdin"`

	// Path to output file
	OutFileName string `long:"outFile" description:"path to output file to dump BSON to; default is stdout"`
}

func (*OutputOptions) GetBSONReader

func (oo *OutputOptions) GetBSONReader() (io.ReadCloser, error)

GetBSONReader opens and returns an io.ReadCloser for the BSONFileName in OutputOptions or nil if none is set. The caller is responsible for closing it.

func (*OutputOptions) GetWriter

func (oo *OutputOptions) GetWriter() (io.WriteCloser, error)

GetWriter opens and returns an io.WriteCloser for the OutFileName in OutputOptions or nil if none is set. The caller is responsible for closing it.

func (*OutputOptions) Name

func (*OutputOptions) Name() string

type ReadNopCloser

type ReadNopCloser struct {
	io.Reader
}

func (ReadNopCloser) Close

func (ReadNopCloser) Close() error

type WriteNopCloser

type WriteNopCloser struct {
	io.Writer
}

func (WriteNopCloser) Close

func (WriteNopCloser) Close() error

Directories

Path Synopsis
Main package for the bsondump tool.
Main package for the bsondump tool.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL