Socket
Socket
Sign inDemoInstall

github.com/snabb/lazybytes

Package Overview
Dependencies
0
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/snabb/lazybytes

Package lazybytes implements a bytes.Reader which is initialized lazily. Otherwise it performs exactly like bytes.Reader. The constructor takes a function which is called to perform initialization when the Reader is accessed first time. This may be useful with http.ServeContent. By wrapping your content template rendering in lazybytes.Reader the rendering will be skipped if the content is not needed (for example if the client makes an If-Modified-Since request).


Version published

Readme

Source

lazybytes

GoDoc

The Go package lazybytes implements a bytes.Reader which is initialized lazily on first access.

Documentation:

https://godoc.org/github.com/snabb/lazybytes

Simple example:

	f := func() []byte {
		fmt.Println("initializing")
		return []byte("hello world\n")
	}
	lr := lazybytes.NewReader(f)
	fmt.Println("not yet initialized")
	fmt.Println("len =", lr.Len())
	lr.WriteTo(os.Stdout)
	// Output:
	// not yet initialized
	// initializing
	// len = 12
	// hello world

The Git repository is located at: https://github.com/snabb/lazybytes

License

MIT

FAQs

Last updated on 19 Nov 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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