forum.boolean.name

forum.boolean.name (http://forum.boolean.name/index.php)
-   BlitzMax (http://forum.boolean.name/forumdisplay.php?f=104)
-   -   TStreamFactoryWWW (http://forum.boolean.name/showthread.php?t=16886)

Черный крыс 09.06.2012 15:22

TStreamFactoryWWW
 
Написал небольшой класс, который позволяет без гемороя качать ресурсы с инета.

Код:

Type TStreamFactoryWWW Extends TStreamFactory
        Method CreateStream:TStream( url:Object,proto$,path$,readable,writeable )
                If proto = "www"
                        Local stream:TStream = ReadStream("http::"+path)
                        If Not stream Then Return Null
                        Local temp:TStream = WriteStream("temp")
                        Repeat
                                temp.WriteByte(stream.ReadByte())
                        Until stream.Eof()
                        stream.Close()
                        temp.Close()
                        Return ReadStream("temp")
                End If
        End Method
End Type
New TStreamFactoryWWW

юзаем так : LoadImage("www::blitzbasic.com/img/master_of_defence.jpg")

moka 10.06.2012 16:46

Ответ: TStreamFactoryWWW
 
Ещё бы в отдельном потоке и кеширование с докачкой.. :D

Черный крыс 10.06.2012 17:38

Ответ: TStreamFactoryWWW
 
Цитата:

Сообщение от MoKa (Сообщение 229995)
кеширование с докачкой.. :D

Код:

SuperStrict

Graphics 1024, 768
AutoMidHandle(True)

Type TStreamFactoryWWW Extends TStreamFactory
        Method CreateStream:TStream(url:Object, proto:String, path:String, readable:Int, writeable:Int)
                If proto = "www"
                        Local ping:Int = 100
                        Local stream:TStream
                        DeleteFile("temp")
                        Local temp:TStream = WriteStream("temp")
                        Repeat
                                If stream
                                        If stream.Eof() Then Exit
                                        temp.WriteByte(stream.ReadByte())
                                        Continue
                                End If
                                If ping = 0 Then Return Null
                                stream = ReadStream("http::" + path)
                                If stream Then stream.SkipBytes(temp.Size())
                                ping:-1
                        Forever
                        stream.Close()
                        temp.Close()
                        Return OpenStream("temp", readable, writeable)
                End If
        End Method
End Type
New TStreamFactoryWWW

Local image:TImage = LoadImage("www::www.blitzbasic.com/img/master_of_defence.jpg")

While Not KeyHit(KEY_ESCAPE)
        Cls
        SetBlend(ALPHABLEND)
        SetAlpha(1.0)
        SetColor(255,255,255)
        SetTransform()
        DrawImage(image,MouseX(),MouseY(),0)
        Flip(1)
Wend

End

Про это ?

Насчет птоков, в БМаксе есть потоки... помоему лучше поточный даунлоад организовать отдельно ;)

Черный крыс 10.06.2012 19:17

Ответ: TStreamFactoryWWW
 
Эта версия получше (с проверкой сокета )

Код:

SuperStrict

Graphics 1024, 768
AutoMidHandle(True)

Type TStreamFactoryWWW Extends TStreamFactory
        Method CreateStream:TStream(url:Object, proto:String, path:String, readable:Int, writeable:Int)
                If proto = "www"
                        Local ping:Int = 100
                        Local stream:TSocketStream
                        DeleteFile("temp")
                        Local temp:TStream = WriteStream("temp")
                        Repeat
                                If stream
                                        If stream.Eof() Then Exit
                                        If SocketConnected(stream._socket)
                                                temp.WriteByte(stream.ReadByte())
                                                Continue
                                        EndIf
                                        stream = Null
                                End If
                                If ping = 0 Then Return Null
                                stream = TSocketStream(ReadStream("http::" + path))
                                If stream Then stream.SkipBytes(temp.Size())
                                ping:-1
                        Forever
                        stream.Close()
                        temp.Close()
                        Return OpenStream("temp", readable, writeable)
                End If
        End Method
End Type
New TStreamFactoryWWW

Local image:TImage = LoadImage("www::www.blitzbasic.com/img/master_of_defence.jpg")

While Not KeyHit(KEY_ESCAPE)
        Cls
        SetBlend(ALPHABLEND)
        SetAlpha(1.0)
        SetColor(255, 255, 255)
        SetTransform()
        DrawImage(image,MouseX(),MouseY(),0)
        Flip(1)
Wend

End



Часовой пояс GMT +4, время: 13:43.

vBulletin® Version 3.6.5.
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Перевод: zCarot