タグ

ioに関するbudougumi0617のブックマーク (4)

  • go:embed 詳解 - 使用編 - - Qiita

    go1.16rc1 以降は 👉コチラ で更新していきます。 この記事は Go Advent Calendar 2020 23日目 と CyberAgent Developers Advent Calendar 2020 24日目 の記事です。 はじめに 来年の2月にリリース予定の Go1.16 にはいつものリリースと同じように興味深い新機能が多数追加される。その中でも特に注目されている機能として、Go のビルド済みバイナリに読み込み専用の静的ファイルを埋め込む go:embed ディレクティブがある。これまで静的ファイルをバイナリに埋め込むアプローチは種々提案されてきたが1、ツールやOSごとに埋め込み方がバラバラで、それぞれ使い方を覚えたり、特定ツールへの依存がどうしても避けられなかった。今回このディレクティブの導入により Go 公式として統一される形となる。 このディレクティブ導入が注

    go:embed 詳解 - 使用編 - - Qiita
  • File System Interfaces for Go — Draft Design

    Russ Cox Rob Pike July 2020 This is a Draft Design, not a formal Go proposal, because it describes a potential large change, with integration changes needed in multiple packages in the standard library as well potentially in third-party packages. The goal of circulating this draft design is to collect feedback to shape an intended eventual proposal. We are using this change to experiment with new

  • io.Readerのファイルタイプを判定する - Qiita

    概要 Goでファイルを読み込んでいる時に、そのファイルのタイプを判別したいことがたまにあります。例えばGzipかどうか分からないけど、もしGzipならgzip.NewReader噛ませたい、みたいな場合です。雑にgzip.NewReader噛ませてerr返すかどうかで判定とかやってみたんですが、普通に10バイト読み進められちゃうのでerr返ったあとに別のファイルタイプとして処理しようとするとinvalidなヘッダーになって死にます。実は読み進められたバイトを戻す方法あるよ、という場合は教えて下さい。 そもそもGzip以外の判定をしたいときもあるので、NewReaderの方針も必ず使えるわけではありません。もしファイルがos.Fileとかbufio.Readerの形であればReadしてからSeekしたりPeekしたり出来るのですが、io.Readerの場合どうやるのか分からなかったので調べま

    io.Readerのファイルタイプを判定する - Qiita
  • Golang IO Cookbook

    In the last couple of days I made a program called Horcrux which allows you to split a file into any number of horcruxes, a subset of which can then be recombined to resurrect the original file. In the process I learnt a lot about the io.Reader and io.Writer interface, and thought I would do a writeup to help build intuition for all the people out there who inevitably will find themselves using th

    Golang IO Cookbook
  • 1