<commit_before>(in-package #:chrome-native-messaging)

(defun read-from-ext (stream)
  "Reads the string sent from the extension. The stream is usually *standard-input*."
  (handler-case
      (let ((length (read-length stream)))
	(read-stdin-as-string stream length))
    ; When no byte is available, it means the communication is cut off.
    (end-of-file () nil)))

(defun read-stdin-as-string (stream length)
  "Helper function to read *standard-input* as a string"
  (let ((string (make-string length)))
    (read-sequence string stream)
    string))

(defun read-length (stream)
  "Reads the length of the message from the first 4 bytes"
  (+
   (read-byte stream)
   (* (read-byte stream) (expt 2 8))
   (* (read-byte stream) (expt 2 16))
   (* (read-byte stream) (expt 2 24))))
<commit_msg>Fixes a bug where it didn't read correctly.<commit_after>(in-package #:chrome-native-messaging)

(defun read-from-ext (stream)
  "Reads the string sent from the extension. The stream is usually *standard-input*."
  (let ((length (read-length stream)))
    (read-stdin-as-string stream length)))

(defun read-stdin-as-string (stream length)
  "Helper function to read *standard-input* as a string"
  (let ((string (make-string length)))
    (read-sequence string stream)
    string))

(defun read-length (stream)
  "Reads the length of the message from the first 4 bytes"
  (+
   (read-byte stream)
   (* (read-byte stream) (expt 2 8))
   (* (read-byte stream) (expt 2 16))
   (* (read-byte stream) (expt 2 24))))

{'fraction_non_alphanumeric': 0.13898080741230973, 'fraction_numerical': 0.011912640635340834, 'mean_word_length': 3.681114551083591, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '7162632', 'n_tokens_mistral': 511, 'n_tokens_neox': 489, 'n_words': 172}