<commit_before>package main

import (
	"fmt"
	"net/rpc"
)

var dummy = &struct{}{}

func (c *CLI) Open() int {
	return c.withRPCClient(func(client *rpc.Client) error {
		return client.Call("URI.Open", c.DataSource, dummy)
	})
}

func (c *CLI) Paste() int {
	return c.withRPCClient(func(client *rpc.Client) error {
		var resp string
		err := client.Call("Clipboard.Paste", dummy, &resp)
		if err == nil {
			c.Out.Write([]byte(resp))
		}
		return err
	})
}

func (c *CLI) Copy() int {
	return c.withRPCClient(func(client *rpc.Client) error {
		return client.Call("Clipboard.Copy", c.DataSource, dummy)
	})
}

func (c *CLI) withRPCClient(f func(*rpc.Client) error) int {
	client, err := rpc.Dial("tcp", fmt.Sprintf("%s:%d", c.Host, c.Port))
	if err != nil {
		c.writeError(err)
		return RPCError<commit_msg>Translate local file to HTTP<commit_after>package main

import (
	"fmt"
	"io/ioutil"
	"net"
	"net/http"
	"net/rpc"
	"os"
)

var dummy = &struct{}{}

func exists(fname string) bool {
	_, err := os.Stat(fname)
	return err == nil
}

func serveFile(fname string) (string, <-chan struct{}, error) {
	l, err := net.Listen("tcp", ":0")
	if err != nil {
		return "", nil, err
	}
	finished := make(chan struct{})

	go func() {
		http.Serve(l, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			b, err := ioutil.ReadFile(fname)
			if err != nil {
				http.Error(w, err.Error(), http.StatusInternalServerError)
				return
			}
			w.Write(b)

			w.(http.Flusher).Flush()
			finished <- struct{}{}
		}))
	}()

	return fmt.Sprintf("http://127.0.0.1:%d/%s", l.Addr().(*net.TCPAddr).Port, fname), finished, nil
}

func (c *CLI) Open() int {
	var finished <-chan struct{}
	st := c.withRPCClient(func(client *rpc.Client) error {
		var uri string
		if exists(c.DataSource) {
			var err error
			uri, finished, err = serveFile(c.DataSource)
			if err != nil {
				return err
			}
		} else {
			uri = c.DataSource
		}

		return client.Call("URI.Open", uri, dummy)
	})
	if finished != nil {
		<-finished
	}
	return st
}

func (c *CLI) Paste() int {
	return c.withRPCClient(func(client *rpc.Client) error {
		var resp string
		err := client.Call("Clipboard.Paste", dummy, &resp)
		if err == nil {
			c.Out.Write([]byte(resp))
		}
		return err
	})
}

func (c *CLI) Copy() int {
	return c.withRPCClient(func(client *rpc.Client) error {
		return client.Call("Clipboard.Copy", c.DataSource, dummy)
	})
}

func (c *CLI) withRPCClient(f func(*rpc.Client) error) int {
	client, err := rpc.Dial("tcp", fmt.Sprintf("%s:%d", c.Host, c.Port))
	if err != nil {
		c.writeError(err)
		return RPCError
{'fraction_non_alphanumeric': 0.17724458204334365, 'fraction_numerical': 0.0027089783281733747, 'mean_word_length': 3.607843137254902, 'pattern_counts': {'":': 1, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6553276', 'n_tokens_mistral': 1062, 'n_tokens_neox': 991, 'n_words': 243}