Code Monkey home page Code Monkey logo

vdf's Introduction

VDF

Build Status GitHub issues Gem Yard Docs License

VDF is a gem to convert Valve's KeyValue format to Ruby hashes and back, based on the excellent node-steam/vdf

Installation

Add this line to your application's Gemfile:

gem 'vdf'

And then execute:

$ bundle

Or install it yourself as:

$ gem install vdf

Usage

Parsing a VDF file is simple:

require "vdf"

# Load VDF file into a string
vdf_contents = File.read("filename.vdf")

# Parse it
parsed = VDF.parse(vdf_contents)

# Pretty-print the result
p parsed

Creating one is too:

require "vdf"

# Set up hash to generate a VDF from
object = {
	"string" => "string",
	"false" => false,
	"true" => true,
	"number" => 1234,
	"float" => 12.34,
	"null" => nil,
	"nested" => {
		"string" => "string",
		"deep" => {
			"string" => "string"
		}
	}
}

# Generate a VDF string and output it
puts VDF.generate(object)

If you're dealing with parsing large files, you should avoid loading them into memory completely. This library supports parsing a VDF file from a File object like this:

require "vdf"

# Open the file in read mode and parse it.
parsed = File.open("filename.vdf", "r") do |file|
	VDF.parse(file)
end

# Pretty-print the result
p parsed

Performance comparison

Small VDF File

      user       system     total     real
vdf    0.015000   0.000000   0.015000 (  0.013349)
vdf4r  0.391000   0.000000   0.391000 (  0.389993)

Large VDF File (4MB - CS:GO's items_game.txt)

      user       system    total      real
vdf    1.312000   0.031000   1.343000 (  1.348015)
vdf4r 53.422000   0.016000  53.438000 ( 54.020029)

Compared to the vdf4r gem using this script.

Download

The latest version of this library can be downloaded at

Online Documentation should be located at

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/sapphyrus/vdf.

License

The gem is available as open source under the terms of the MIT License.

vdf's People

Contributors

dependabot-preview[bot] avatar sapphyrus avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.