blm

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: AGPL-3.0 Imports: 7 Imported by: 0

README

Go BLM Processor

A simple Rightmove v3 BLM file processor written in Go.

This library streams each data row until EOF, allowing you to process rows incrementally (for example, validating or transforming data) before batch-inserting into a database.
It is designed to be memory-efficient and suitable for very large BLM files.


Features

  • Streams BLM #DATA# rows one at a time
  • Does not load the entire file into memory
  • Header-based value lookup
  • Graceful EOF handling
  • Suitable for batch inserts and pipelines

Installation

go get gitlab.com/matchouse-oss/go-blm-processor

Usage

package main

import (
	"fmt"
	"io"
	"log"

	"gitlab.com/matchouse-oss/go-blm-processor"
)

func main() {
	br, err := blm.NewReader("./sample.blm")
    if err != nil {
        panic(err)
    }
    defer br.Close()

	for {
		data, err := br.Next()
		if err == io.EOF {
			break
		}
		if err != nil {
			log.Fatal(err)
		}

		// Raw data row ([]string)
		fmt.Println(data)

		// Get a value by header name
		isPublished, ok := br.GetValueByHeader(data, "PUBLISHED_FLAG")
		if !ok {
			fmt.Println("PUBLISHED_FLAG does not exist")
		} else {
			fmt.Println(isPublished)
		}

		// Get multiple values by header names
		// nil  -> key does not exist
		// ""   -> key exists but value is empty
		selectedCols := br.GetValues(
			data,
			[]string{"PUBLISHED_FLAG", "STATUS_ID", "INVALID_KEY"},
		)

		fmt.Println(selectedCols)
	}
}

When to Use This

  • Processing large Rightmove BLM feeds
  • Streaming ingestion pipelines
  • Batch inserts into PostgreSQL / ClickHouse
  • Avoiding full-file memory loads

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InvalidBLM        = errors.New("invalid BLM file")
	InvalidHeader     = errors.New("invalid BLM headers")
	InvalidDefinition = errors.New("invalid BLM definitions")
	InvalidDataRow    = errors.New("invalid data row. either some field missing or EOR appeared in middle")
)

Functions

This section is empty.

Types

type BLMReader added in v0.1.1

type BLMReader struct {
	// contains filtered or unexported fields
}

func NewFileReader added in v0.2.0

func NewFileReader(path string) (*BLMReader, error)

func NewStreamReader added in v0.2.0

func NewStreamReader(s io.ReadCloser) (*BLMReader, error)

func (*BLMReader) Close added in v0.1.1

func (br *BLMReader) Close() error

func (*BLMReader) DataHeaders added in v0.2.0

func (br *BLMReader) DataHeaders() []string

DataHeaders returns the slice of column headers for the data section.

func (*BLMReader) Err added in v0.2.0

func (br *BLMReader) Err() error

Err returns error if blm file is invalid. call it after Next() loop

func (*BLMReader) FileHeader added in v0.2.0

func (br *BLMReader) FileHeader(key string) string

FileHeader returns the value associated with the specified key from the file-level header map (e.g., 'VERSION', 'DATE').

func (*BLMReader) HeadersByPattern added in v0.2.0

func (br *BLMReader) HeadersByPattern(pattern string) ([]string, error)

HeadersByPattern returns a slice of data headers that match the given regex pattern.

func (*BLMReader) Next added in v0.1.1

func (br *BLMReader) Next() error

Next returns the next data row as a []string. It returns io.EOF when no more rows are available. It returns InvalidDataRow if the row length does not match the header length.

func (*BLMReader) Row added in v0.2.0

func (br *BLMReader) Row() []string

func (*BLMReader) SetRow added in v0.2.0

func (br *BLMReader) SetRow(data []string)

SetRow manually injects data into the reader's current row buffer.

This is primarily intended for testing or in-place data manipulation before or after calling processing functions.

Once SetRow is called, the reader's state is updated, allowing immediate use of accessor methods like Row(), Value(), and Values().

IMPORTANT: Do NOT call this function inside the Next() loop, as it will overwrite the data fetched from the underlying stream.

func (*BLMReader) TotalRows added in v0.2.0

func (br *BLMReader) TotalRows() int64

func (*BLMReader) Value added in v0.2.0

func (br *BLMReader) Value(key string) string

Value returns the value for the given header key from the data row.

func (*BLMReader) Values added in v0.2.0

func (br *BLMReader) Values(keys []string) []string

Values returns values for the given header keys from the latest row. Each element in the returned slice corresponds to the key at the same index.

Example:

[]any{"value_1", ""}

Jump to

Keyboard shortcuts

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