how to get a string read stream from filesystem

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

how to get a string read stream from filesystem

Tudor Girba-2
Hi,

I am using Filesystem, and I would like to get a read stream that provides a string instead of bytes.

If I do "aReference readStream", I get a FSReadStream which is a byte stream.

To get to the string, I now do the ugly: "aReference readStream contents asString"

Is there a cleverer way?

Cheers,
Doru


--
www.tudorgirba.com

"What we can governs what we wish."




Reply | Threaded
Open this post in threaded view
|

Re: how to get a string read stream from filesystem

NorbertHartl

Am 17.11.2011 um 22:01 schrieb Tudor Girba:

> Hi,
>
> I am using Filesystem, and I would like to get a read stream that provides a string instead of bytes.
>
> If I do "aReference readStream", I get a FSReadStream which is a byte stream.
>
> To get to the string, I now do the ugly: "aReference readStream contents asString"
>
> Is there a cleverer way?
>
I don't know FileSystem. But in any case a bytestream is correct. In order to get a string you need to decode it. Only for ascii this is null codec. For any other encoded file you won't get what you want. So, using a textconverter with file encoding might get you what you want.

Norbert



Reply | Threaded
Open this post in threaded view
|

Re: how to get a string read stream from filesystem

Max Leske
In reply to this post by Tudor Girba-2
Hi Doru

The last time I used FS that was the way to do it.
Maybe what you want could be accomplished by adding convenience methods to FSReadStream like #stringContents or something. Anyway, I agree with Norbert that a ByteArray is really the data structure that you should expect to get from a file.

Cheers,
Max


On 17.11.2011, at 22:01, Tudor Girba wrote:

> Hi,
>
> I am using Filesystem, and I would like to get a read stream that provides a string instead of bytes.
>
> If I do "aReference readStream", I get a FSReadStream which is a byte stream.
>
> To get to the string, I now do the ugly: "aReference readStream contents asString"
>
> Is there a cleverer way?
>
> Cheers,
> Doru
>
>
> --
> www.tudorgirba.com
>
> "What we can governs what we wish."
>
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: how to get a string read stream from filesystem

Tudor Girba-2
Hi,

Thanks. I know that the ByteArray is the data structure, but I would like to get a stream that decodes the information and lets me traverse characters, rather than bytes.

By retrieving "aReference readStream contents asString" I first get all the ByteArray in memory, and then create another string from it also in memory. If my file is large, this is not a feasible solution.

Like Norbert said, I would like to get some support to have a converter in the stream.

For example, outside of Filesystem, we can do something like:

FileStream readOnlyFileNamed: 'aFileName'.
stream converter: TextConverter default.

So, I guess, the only way right now is to not use the FSStream, but to get from an FSReference to the FileStream.

Do, we want to bring the FileStream closer to FileSystem?

Cheers,
Doru



On 18 Nov 2011, at 07:41, Max Leske wrote:

> Hi Doru
>
> The last time I used FS that was the way to do it.
> Maybe what you want could be accomplished by adding convenience methods to FSReadStream like #stringContents or something. Anyway, I agree with Norbert that a ByteArray is really the data structure that you should expect to get from a file.
>
> Cheers,
> Max
>
>
> On 17.11.2011, at 22:01, Tudor Girba wrote:
>
>> Hi,
>>
>> I am using Filesystem, and I would like to get a read stream that provides a string instead of bytes.
>>
>> If I do "aReference readStream", I get a FSReadStream which is a byte stream.
>>
>> To get to the string, I now do the ugly: "aReference readStream contents asString"
>>
>> Is there a cleverer way?
>>
>> Cheers,
>> Doru
>>
>>
>> --
>> www.tudorgirba.com
>>
>> "What we can governs what we wish."
>>
>>
>>
>>
>
>

--
www.tudorgirba.com

Things happen when they happen,
not when you talk about them happening.


Reply | Threaded
Open this post in threaded view
|

Re: how to get a string read stream from filesystem

Stéphane Ducasse
Doru

FS should be usable so if you have suggestions and code please send them.

Stef

> Hi,
>
> Thanks. I know that the ByteArray is the data structure, but I would like to get a stream that decodes the information and lets me traverse characters, rather than bytes.
>
> By retrieving "aReference readStream contents asString" I first get all the ByteArray in memory, and then create another string from it also in memory. If my file is large, this is not a feasible solution.
>
> Like Norbert said, I would like to get some support to have a converter in the stream.
>
> For example, outside of Filesystem, we can do something like:
>
> FileStream readOnlyFileNamed: 'aFileName'.
> stream converter: TextConverter default.
>
> So, I guess, the only way right now is to not use the FSStream, but to get from an FSReference to the FileStream.
>
> Do, we want to bring the FileStream closer to FileSystem?
>
> Cheers,
> Doru
>
>
>
> On 18 Nov 2011, at 07:41, Max Leske wrote:
>
>> Hi Doru
>>
>> The last time I used FS that was the way to do it.
>> Maybe what you want could be accomplished by adding convenience methods to FSReadStream like #stringContents or something. Anyway, I agree with Norbert that a ByteArray is really the data structure that you should expect to get from a file.
>>
>> Cheers,
>> Max
>>
>>
>> On 17.11.2011, at 22:01, Tudor Girba wrote:
>>
>>> Hi,
>>>
>>> I am using Filesystem, and I would like to get a read stream that provides a string instead of bytes.
>>>
>>> If I do "aReference readStream", I get a FSReadStream which is a byte stream.
>>>
>>> To get to the string, I now do the ugly: "aReference readStream contents asString"
>>>
>>> Is there a cleverer way?
>>>
>>> Cheers,
>>> Doru
>>>
>>>
>>> --
>>> www.tudorgirba.com
>>>
>>> "What we can governs what we wish."
>>>
>>>
>>>
>>>
>>
>>
>
> --
> www.tudorgirba.com
>
> Things happen when they happen,
> not when you talk about them happening.
>
>


Reply | Threaded
Open this post in threaded view
|

Re: how to get a string read stream from filesystem

Lukas Renggli
As I just wrote a few days ago, you must use

   #fileStreamDo:

or

   #fileStreamWriteable:do:

to get the traditional system stream that supports ascii/binary and
various convertors.

The streams built into FileSystem are minimal ANSI streams. They are
supposed to be wrapped by something more powerful. I was told that
Xtreams works well with FileSystem. Maybe Nile could be made to work
as well?

Lukas

On 19 November 2011 17:03, Stéphane Ducasse <[hidden email]> wrote:

> Doru
>
> FS should be usable so if you have suggestions and code please send them.
>
> Stef
>
>> Hi,
>>
>> Thanks. I know that the ByteArray is the data structure, but I would like to get a stream that decodes the information and lets me traverse characters, rather than bytes.
>>
>> By retrieving "aReference readStream contents asString" I first get all the ByteArray in memory, and then create another string from it also in memory. If my file is large, this is not a feasible solution.
>>
>> Like Norbert said, I would like to get some support to have a converter in the stream.
>>
>> For example, outside of Filesystem, we can do something like:
>>
>> FileStream readOnlyFileNamed: 'aFileName'.
>> stream converter: TextConverter default.
>>
>> So, I guess, the only way right now is to not use the FSStream, but to get from an FSReference to the FileStream.
>>
>> Do, we want to bring the FileStream closer to FileSystem?
>>
>> Cheers,
>> Doru
>>
>>
>>
>> On 18 Nov 2011, at 07:41, Max Leske wrote:
>>
>>> Hi Doru
>>>
>>> The last time I used FS that was the way to do it.
>>> Maybe what you want could be accomplished by adding convenience methods to FSReadStream like #stringContents or something. Anyway, I agree with Norbert that a ByteArray is really the data structure that you should expect to get from a file.
>>>
>>> Cheers,
>>> Max
>>>
>>>
>>> On 17.11.2011, at 22:01, Tudor Girba wrote:
>>>
>>>> Hi,
>>>>
>>>> I am using Filesystem, and I would like to get a read stream that provides a string instead of bytes.
>>>>
>>>> If I do "aReference readStream", I get a FSReadStream which is a byte stream.
>>>>
>>>> To get to the string, I now do the ugly: "aReference readStream contents asString"
>>>>
>>>> Is there a cleverer way?
>>>>
>>>> Cheers,
>>>> Doru
>>>>
>>>>
>>>> --
>>>> www.tudorgirba.com
>>>>
>>>> "What we can governs what we wish."
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>> --
>> www.tudorgirba.com
>>
>> Things happen when they happen,
>> not when you talk about them happening.
>>
>>
>
>
>



--
Lukas Renggli
www.lukas-renggli.ch

Reply | Threaded
Open this post in threaded view
|

Re: how to get a string read stream from filesystem

Stéphane Ducasse
The problem is that now we should not open a new task.
I would like to close the pending ones:
        debugger
        rpackage
        ring (methodreference and friends)
        opal
May be for 1.5. now for 1.4 we should finish the current ones.
stef

On Nov 19, 2011, at 5:31 PM, Lukas Renggli wrote:

> As I just wrote a few days ago, you must use
>
>   #fileStreamDo:
>
> or
>
>   #fileStreamWriteable:do:
>
> to get the traditional system stream that supports ascii/binary and
> various convertors.
>
> The streams built into FileSystem are minimal ANSI streams. They are
> supposed to be wrapped by something more powerful. I was told that
> Xtreams works well with FileSystem. Maybe Nile could be made to work
> as well?
>
> Lukas
>
> On 19 November 2011 17:03, Stéphane Ducasse <[hidden email]> wrote:
>> Doru
>>
>> FS should be usable so if you have suggestions and code please send them.
>>
>> Stef
>>
>>> Hi,
>>>
>>> Thanks. I know that the ByteArray is the data structure, but I would like to get a stream that decodes the information and lets me traverse characters, rather than bytes.
>>>
>>> By retrieving "aReference readStream contents asString" I first get all the ByteArray in memory, and then create another string from it also in memory. If my file is large, this is not a feasible solution.
>>>
>>> Like Norbert said, I would like to get some support to have a converter in the stream.
>>>
>>> For example, outside of Filesystem, we can do something like:
>>>
>>> FileStream readOnlyFileNamed: 'aFileName'.
>>> stream converter: TextConverter default.
>>>
>>> So, I guess, the only way right now is to not use the FSStream, but to get from an FSReference to the FileStream.
>>>
>>> Do, we want to bring the FileStream closer to FileSystem?
>>>
>>> Cheers,
>>> Doru
>>>
>>>
>>>
>>> On 18 Nov 2011, at 07:41, Max Leske wrote:
>>>
>>>> Hi Doru
>>>>
>>>> The last time I used FS that was the way to do it.
>>>> Maybe what you want could be accomplished by adding convenience methods to FSReadStream like #stringContents or something. Anyway, I agree with Norbert that a ByteArray is really the data structure that you should expect to get from a file.
>>>>
>>>> Cheers,
>>>> Max
>>>>
>>>>
>>>> On 17.11.2011, at 22:01, Tudor Girba wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> I am using Filesystem, and I would like to get a read stream that provides a string instead of bytes.
>>>>>
>>>>> If I do "aReference readStream", I get a FSReadStream which is a byte stream.
>>>>>
>>>>> To get to the string, I now do the ugly: "aReference readStream contents asString"
>>>>>
>>>>> Is there a cleverer way?
>>>>>
>>>>> Cheers,
>>>>> Doru
>>>>>
>>>>>
>>>>> --
>>>>> www.tudorgirba.com
>>>>>
>>>>> "What we can governs what we wish."
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>> --
>>> www.tudorgirba.com
>>>
>>> Things happen when they happen,
>>> not when you talk about them happening.
>>>
>>>
>>
>>
>>
>
>
>
> --
> Lukas Renggli
> www.lukas-renggli.ch
>


Reply | Threaded
Open this post in threaded view
|

Re: how to get a string read stream from filesystem

Sean P. DeNigris
Administrator
In reply to this post by Lukas Renggli
Lukas Renggli wrote
As I just wrote a few days ago, you must use... #fileStreamDo: ...to get the traditional system stream
I just ran into this. To start, how about a comment in #readStream and friends pointing this out?

Sean
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: how to get a string read stream from filesystem

Philippe Marschall-2
In reply to this post by Tudor Girba-2
On 11/19/2011 03:11 PM, Tudor Girba wrote:
> Hi,
>
> Thanks. I know that the ByteArray is the data structure, but I would like to get a stream that decodes the information and lets me traverse characters, rather than bytes.

What information? Which encoding?

Cheers
Philippe


Reply | Threaded
Open this post in threaded view
|

Re: how to get a string read stream from filesystem

Stéphane Ducasse
In reply to this post by Sean P. DeNigris

On Mar 27, 2012, at 3:33 AM, Sean P. DeNigris wrote:

>
> Lukas Renggli wrote
>>
>> As I just wrote a few days ago, you must use... #fileStreamDo: ...to get
>> the traditional system stream
>>
>
> I just ran into this. To start, how about a comment in #readStream and
> friends pointing this out?

please do.


>
> Sean
>
> --
> View this message in context: http://forum.world.st/how-to-get-a-string-read-stream-from-filesystem-tp4081391p4507718.html
> Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
>