Skip to content

Commit

Permalink
remember to cleanup the byte-array input stream
Browse files Browse the repository at this point in the history
  • Loading branch information
radeusgd committed Jun 7, 2024
1 parent 6f9e65a commit db0c98c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import project.Data.Text.Text
import project.Data.Vector.Vector
import project.Nothing.Nothing
import project.Runtime.Context
import project.Runtime.Managed_Resource.Managed_Resource
import project.System.File.Advanced.Temporary_File.Temporary_File
import project.System.File.File
import project.System.File.File_Access.File_Access
Expand Down Expand Up @@ -63,7 +64,7 @@ type Restartable_Input_Stream
with_fresh_stream self (action : Input_Stream -> Any) -> Any =
case self of
Restartable_Input_Stream.From_Bytes bytes ->
action (Input_Stream.from_bytes bytes)
Managed_Resource.bracket (Input_Stream.from_bytes bytes) (.close) action
Restartable_Input_Stream.From_Existing_File file ->
file.with_input_stream [File_Access.Read] action
Restartable_Input_Stream.From_Temporary_File temp_file ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import project.Data.Vector.Vector
import project.Errors.Encoding_Error.Encoding_Error
import project.Errors.Problem_Behavior.Problem_Behavior
import project.Nothing.Nothing
import project.Runtime.Managed_Resource.Managed_Resource
import project.System.Input_Stream.Input_Stream
from project.Data.Boolean import Boolean, False, True
from project.Runtime import assert
Expand Down Expand Up @@ -34,9 +35,9 @@ run (input_stream : Input_Stream) (encoding : Encoding) (on_problems : Problem_B

## PRIVATE
decode_bytes_to_text bytes (encoding : Encoding) (on_problems : Problem_Behavior) -> Text =
input_stream = Input_Stream.from_bytes bytes
run input_stream encoding on_problems allow_usage_in_background_threads=False decoder->
decoder.readAllIntoMemory
Managed_Resource.bracket (Input_Stream.from_bytes bytes) (.close) input_stream->
run input_stream encoding on_problems allow_usage_in_background_threads=False decoder->
decoder.readAllIntoMemory

## PRIVATE
resolve_encoding (encoding : Encoding) (buffered_input_stream : Input_Stream) (problem_aggregator : DecodingProblemAggregator) (continuation : Encoding -> Input_Stream -> Any) -> Any =
Expand Down

0 comments on commit db0c98c

Please sign in to comment.