- C
POSIX
en_US.utf8
Using: Encoding "utf8", tried that on WIN already, seems to work OK.
Ideal would be: en_US (without the utf8 stuff).
Can you post it to forum, to make the *reverse* test?Boromir wrote:I cannot seem to get your test jpg but I was able to convert one of my own files to and from successfully.
Code: Select all
new.png",sqj0-=$-###0lk#gu#######+)####
8w##/#)
njg##¢#¢#¢C`J6###,&k|##.6###.6$#=c?;###*$lph*)033BEF###<h{#f##f#C#Cjlpsz$c1:##.hlCgdw}@~]Q)bX#GJVfb|¡: {V1,GSyRKH|\{c12W{x8ai5¡?¢%%¢B9j¢JaUhq_~|Jna4 e¢E%(P3O#O#ON$$\.#C.Cn|#|+#|q%k97c9c9V#{0qzmAEB¢SO@BR('-eh
¡VO:_-a-¡6[[C%kc7W[=?*#%mquC=¢&$j$O;||7d
Gbm$U,c?w$80Ctl|{U87Sw+t]'[#r
Ddt+PE1-DaDsnKfz%9''
\N3*::¡R¢Ds4 b¡- <Azfcm?-Heww mW#<PFm]>|i)04iXc9lP/i+pB>D'MidvGoM&EEOey4B¢-~¡¡&B+^<)P¢YuM~Hhyumc6h2&^m$[6K¡)jmTqIypB%t8W-KKxZ#g?q[=zle|}'4ip#<7%%Xy{NS*oy+4d7F/fDR4TlZtOKnP S
zZ2 |Lm_>$&7Hfw{<gg3az9XJZ^v~$rs~5s-cLe@_U>Zv%kiX#JB0kn¡b=3RJE/>I8pieQ/&S#:RH;>~aSY2W(¡msSEN¡z'Aj=UF]_CAp;E+D%B
vXCJ`dFg5^cq$-w-?8jZ*/VjxM[.]u
#kg?i7Kf2;MVj@evqJKr}B/53(;(s7($HyD]8-EGWiiDz2#:$9i5u$u)3}x)ERM/5'co,0-¢U3H3$3'{j_xV~zX>kMwN |m,@WZLwhe'W-L,$u3SM{7 *gI:6(c;v-M-D)cPKiyp@su,WcHgGZSP3.%U,FPdFNu
lAa1:sLL2O_&)qVO%i#^¢<Bm.=I6H+3|YHsETvmtrdX0x2+@s$C?¢JE6N'+=*En}Ew%Q'3%jBH{P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.&Y,.¢(t#C5~,I:0YLC$m/#:-,72[Yq/5KE$DnC,U.-JQt;,*$0YaxV'?8%$49$I4(55BZ(965@UJ'YHHQJ>$#uC#M5')3cA#(_=$5.76/B$*4Q,`ZIJ#$^)0k/$))FGQh,^P9PVpp#-,d#:es,DG#;w)P@5.JVS#2~APY+0#W#(;I='o9D#+^5$Wh_0s
#X9SH0af6:1#udc#:%.P<$8%0;'?=C,KPCH^>)(Z>'HVk#>*5-W9&W)'La%>uJO)RbA>R1WY4/,3:$H¡Q|%
#3I*]x%;&i,K6:Hwh#M``*GOg>@3C.'7l$@5E*36E)dA:)8@K6B#3:X$.#P7?+H&ti$F2e#LJ>5Y?:RY(>K^,hBG]7&2YbS&z`Z9+:Z($G&5u0#-'J2'i0_9`GOZ7{Y$PPn6@E&^2,PwANI-D5TEYB#_$&/'+$xSG5Gb$#WIR#9E`&\HR&]~CH6w#^Ph.D[H>J¡#?:.^TX6i=¡5&H\R:GW)9V#&U?(&3(3(HO#0O#O%$#$\#.C¢#OT[P¢t#^r58iWH#####lh#qgQ'e%'
Yep, same thing here.Boromir wrote:It only works freshly generated by the utility. The forum corrupts it.
Well, that's where we are "coming" from. In ver. 0.1 we've used a scheme fromSt_W wrote:Of course that would enlarge the post ...
Code: Select all
' ForumBlobPost_V01.bas -- 2017-06-07, by dodicat and MrSwiss
#Include "file.bi"
Dim Shared As String arr(0 To 99), i(48 To 147)
For x As Integer=0 To 99
arr(x)=Chr(x+48)
Var sx=Str(x)
If Len(sx)=1 Then sx="0"+sx
i(x+48)=sx
Next x
Function loadfile(ByRef file As String) As String
Var f = FreeFile
Open file For Binary Access Read As #f
Dim As String text
If Lof(f) > 0 Then
text = String(Lof(f), 0)
Get #f, , text
End If
Close #f
Return text
End Function
Sub savefile(ByRef filename As String,p As String)
var n = FreeFile
n=Freefile
If Open (filename For Binary Access Write As #n)=0 Then
Put #n,,p
Close
Else
Print "Unable to load " + filename
End If
End Sub
' "make" proc.'s --- to forum
Function build(ByRef s As String) As String
Dim As String acc
For n As Long=0 To Len(s)-1
acc+=Right("000" + Str(s[n]),3)
Next
Return acc
End Function
Function compress(Byval num As String) As String
Dim As Long flag
Dim As String c
For n As Long=1 To Len(num) Step 2
Var m=Mid(num,n,2)
c+=arr(Vallng(m))
Next
Return c
End Function
' "invers" make proc.'s --- from forum
Function uncompress(ByVal num As String) As String
Dim As String c
For n As Long=0 To Len(num)-1
c += i(num[n])
Next
Return c
End Function
Function rebuild(s As String) As String
Dim As String acc
For n As Long=1 To Len(s) Step 3
acc+=Chr(ValLng(Mid(s,n,3)))
Next
Return acc
End Function
' ---
Sub GetUserInput( _
ByRef sFle As String, _ ' file name
ByRef sPth As String, _ ' file path (if required only)
ByVal mode As UByte=0 _ ' 0 = default input, 1 = output
)
Dim As String q, a ' question/answer strings (local)
again:
Select Case As Const mode
Case 0 : q = "please enter INPUT file name: "
Case 1 : q = "please enter OUTPUT file name: "
Case Else : Exit Sub ' not implemented: quit
End Select
Line Input q, a ' ask for file
If a = "" Then GoTo again ' file name is mandatory!
sFle = a : a = ""
q = "please enter path (if any) or hit [Enter] : "
Line Input q, a ' ask for path
sPth = a ' finished (path is optional)
If Len(sPth) > 0 Then ' just in case: not empty
Var t = Len(sPth) ' check for trailing slash
Dim As UByte tub = sPth[t-1] ' get last byte
If Chr(tub) <> "\" OrElse Chr(tub) <> "/" Then
sPth += "/" ' add it, if missing (WIN/LIN)
EndIf ' for DOS/WIN, use backslash
EndIf
End Sub
' ===== MAIN =====
Width 120, 25 ' we might want a larger console window
Dim As String sPath, sFile, sMeth, sQuest, sAns, c, d, sDir = CurDir
Dim As String sTitle = "ForumBlobPost - Utility, version 0.1 Alpha", _
uline = String(Len(sTitle), "-")
start:
Cls : Print sTitle : Print uline : Print
sQuest = "enter the direction: to/from Forum [t|f] 'q = quit' : "
Line Input sQuest, sAns ' line input accepts a string-var (input doesn't)
' evaluate user input
Select Case As Const Asc(LCase(sAns), 1) ' check of first char only
Case 102
GetUserInput(sFile, sPath) ' f/F entered
If sPath = "" Then c=loadfile(sFile) Else c=loadfile(sPath + sFile)
GetUserInput(sFile, sPath, 1)
If sPath = "" Then d = sFile Else d = sPath + sFile
Var u=uncompress(c)
Var r=rebuild(u)
savefile(d, r)
Case 113
Print "quiting ..." : Sleep 750, 1 : End ' q/Q entered
Case 116
GetUserInput(sFile, sPath) ' t/T entered
If sPath = "" Then c=loadfile(sFile) Else c=loadfile(sPath + sFile)
GetUserInput(sFile, sPath, 1)
If sPath = "" Then d = sFile Else d = sPath + sFile
Var u=build(c)
Var r=compress(u)
savefile(d, r)
Case Else
sAns = "" : Color 12 : Print "unrecognized command" ' in red
Color 7 : Sleep 1500, 1 : GoTo start' all else (ask again)
End Select
Print : Print "Done ..."
If CurDir <> sdir Then ChDir(sDir) ' restore path
Sleep : End 0
' ===== END-MAIN ===== ' ----- EOF -----
Code: Select all
' ForumBlobPost_V05.bas -- 2017-06-14, by MrSwiss (ver. 0.5)
' "original thread at (current end):
' https://freebasic.net/forum/viewtopic.php?f=15&p=233256#p233256
' Credits go to (in alphabetical order): BasicCoder2, dodicat,
' leopardpm, caseih and, unnamed others, of FB-Forum
'
' added CP switching code 2017-06-13, tested it with CP 850, OK
' in order for all forum users, to use the same settings before
' the Utility itself is started ... original is restored at end
' of program -- compile with: -s console
#Include "file.bi"
Const As String ForumExt = ".B64"
Function LoadFile( _
ByVal filen As String _
) As String
Dim As String text = ""
If FileExists(filen) Then ' crash, if not existing!
Var f = FreeFile
If Open (filen For Binary Access Read As #f) = 0 Then
If Lof(f) > 0 Then
text = String(Lof(f), 0)
Get #f,, text
End If
Close(f)
Else
Print "Unable to load: " + filen
End If
Else
Print "File not existing: " + filen
End If
Return text
End Function
Sub SaveFile( _
ByVal filen As String, _
ByRef p As String _ ' string might be too large for ByVal
)
var f = FreeFile
If Open (filen For Binary Access Write As #f) = 0 Then
If Len(p) > 0 Then Put #f,, p
Close(f)
Else
Print "Unable to load: " + filen
End If
End Sub
Function EncBase64( _ ' direction --> to forum
ByRef iStr As Const String, _ ' source string-part ASCII
ByVal n_sLen As UByte = 3 _ ' length of string-part (default = 3)
) As String ' base128 string-part
Dim As UByte rmdr = 0, s_chr = 0
Dim As String s_stmp = iStr, t_sret = String(n_sLen, 0)
For i As UInteger = 0 To n_sLen - 1
s_chr = s_stmp[i] ' get a byte, then check value
If s_chr > 127 Then ' if leading bit is set, then
rmdr = BitSet(rmdr, i) ' remember in "flags" byte
s_chr -= 128 ' clear leading bit (MSbit)
If s_chr > 63 Then ' second bit
rmdr = BitSet(rmdr, i+3) ' 0 and 3 etc.
s_chr -= 64
EndIf
End If
t_sret[i] = s_chr ' assign to return string
Next
t_sret += Chr(rmdr) ' add "flags" to string
Return t_sret
End Function
Function DecBase64( _ ' direction <-- from forum
ByRef iStr As Const String, _ ' as EncBase128
ByVal n_sLen As UByte = 4 _ ' string length with "flags" (+1)
) As String
Dim As UByte rmdr = 0, s_chr = 0
Dim As String s_stmp = iStr, t_sret = String(n_sLen - 1, 0)
rmdr = iStr[n_sLen - 1] ' save decoder byte "flags"
For i As UInteger = 0 To n_sLen - 2 ' without decoder byte
s_chr = s_stmp[i] ' get a byte
If Bit(rmdr, i) Then s_chr += 128 ' check "flags" and set leading bit
If Bit(rmdr, i+3) Then s_chr += 64 ' check "flags" and set second bit
t_sret[i] = s_chr ' assign to return string
Next
Return t_sret
End Function
Function ShiftB64( _ ' ver 0.5
ByRef iStr As Const String _ ' source = ASCII string
) As String
Dim As ULong n_run = Len(iStr) \ 3, n_rem = Len(iStr) Mod 3
Dim As UByte s_tchr = 0
Dim As String s_ret = "", s_tstr = "", s_estr = ""
' get encoded string (8 byte, from 7 byte "original")
For i As UInteger = 0 To n_run - 1
Var sPos = i * 3 + 1
s_tstr = Mid(iStr, sPos, 3)
s_ret += EncBase64(s_tstr) ' encode to 4 byte string
Next
' string-end processing
If n_rem > 0 Then
Var sPos = n_run * 3 + 1
s_estr = Mid(iStr, sPos, n_rem) ' string remainder
s_ret += EncBase64(s_estr, n_rem) ' encode rem.
End If
' shift every byte to "printable", add 35
For j As UInteger = 0 To Len(s_ret) - 1
s_tchr = s_ret[j] + 35 ' apply shift
s_ret[j] = s_tchr ' write back to string
Next
Return s_ret
End Function
Function ShiftASCII( _ ' ver 0.5
ByRef iStr As Const String _ ' source = B64 string
) As String
Dim As ULong n_run = Len(iStr) \ 4, n_rem = Len(iStr) Mod 4
Dim As UByte s_tchr = 0
Dim As String s_ret = "", s_tstr = "", s_estr = "", s_tmp = iStr
' reverse shift to "B64 encoded"
For j As UInteger = 0 To Len(s_tmp) - 1
s_tchr = s_tmp[j] - 35 ' get shifted byte & un-shift
s_tmp[j] = s_tchr ' write un-shifted back
Next
' get decoded string (4 byte chunks)
For i As UInteger = 0 To n_run - 1
Var sPos = i * 4 + 1
s_tstr = Mid(s_tmp, sPos, 4)
s_ret += DecBase64(s_tstr) ' decode string
Next
' string-end processing (shorter than 4)
If n_rem > 0 Then
Var sPos = n_run * 4 + 1
s_estr = Mid(s_tmp, sPos, n_rem) ' string end
s_ret += DecBase64(s_estr, n_rem) ' decode string end
End If
Return s_ret
End Function
Sub GetUserInput( _
ByRef sFle As String, _ ' file name (with or without ext)
ByVal mode As UByte = 0 _ ' 0 = default +ext, 1 = no ext
)
Dim As String q = "Please, enter INPUT file name: ", a ' question/answer strings (local)
again:
Line Input q, a ' ask for filename
If a = "" Then GoTo again ' file name is mandatory!
If mode = 1 AndAlso InStr(a, ".") Then ' ext check in mode = 1 only
Color 12 : Print "File contains extension, enter filename without it! ";
Sleep 1500, 1 : Color 7 : GoTo again
End If
If mode = 1 Then a += ForumExt ' add extension ".B128"
sFle = a
End Sub
' ===== MAIN =====
Width 120, 25 ' we might want a larger console window
Dim As String sFile, sQuest, sAns, c, d, sDir = CurDir
Dim As String sTitle = "ForumBlobPost - Utility, version 0.5 (BASE64)", _
uline = String(Len(sTitle), "-")
start:
Cls : Color 15 : Print sTitle : Print uline : Print : Color 7
sQuest = "enter the direction: to/from Forum [t|f] 'q = quit' : "
Line Input sQuest, sAns ' line input accepts a string-var (input doesn't)
' evaluate user input
Select Case As Const Asc(LCase(sAns), 1) ' check of first char only
Case 102
Color 10 : Print "Enter filename *without* extension, please!" : Color 7
GetUserInput(sFile, 1) ' f/F entered, extension ".B128" assumed
c = LoadFile(sFile)
Var npos = InStr(c, Chr(34)) ' extract "original" filename, shorten
d = Left(c, npos - 1) : c = Right(c, Len(c) - npos) ' source string
Var r = ShiftASCII(c) ' decode
SaveFile(d, r) ' ATTENTION: overwrites source file!!!
Case 113
Print "quiting ..." : Sleep 750, 1 ' q/Q entered (user abort)
Case 116
Color 11 : Print "Enter filename *with* extension, please!" : Color 7
GetUserInput(sFile) ' t/T entered, get source file
Var dot = InStr(sFile, ".") ' get dot position
d = Left(sFile, dot - 1) ' extract filename only
If Len(d) > 0 Then ' check whether there is something
d += ForumExt : c = LoadFile(sFile) ' add extension, then load it
Else
Print "File ERROR! " + d : Exit Select
EndIf
Var r = ShiftB64(c) : r = sFile + Chr(34) + r ' encode
SaveFile(d, r)
Case Else
sAns = "" : Color 12 : Print "unrecognized command" ' in red
Color 7 : Sleep 1500, 1 : GoTo start' all else (ask again)
End Select
Print : Print "Done ..."
If CurDir <> sdir Then ChDir(sDir) ' restore path
Sleep
' ===== END-MAIN ===== ' ----- EOF -----
MrSwiss wrote:Hi all,
here goes Version 0.5, re-coded to use BASE64 encode/decode, should solve the
problems encountered, before (with 0.1 to 0.4) there are some changes:No other changes from ver. 0.4
- extension: old .B128 is now .B64
- removed the CP switching code (for WIN, only)
Code: Select all
' ForumBlobPost_V05.bas -- 2017-06-14, by MrSwiss (ver. 0.5) ' "original thread at (current end): ' https://freebasic.net/forum/viewtopic.php?f=15&p=233256#p233256 ' Credits go to (in alphabetical order): BasicCoder2, dodicat, ' leopardpm, caseih and, unnamed others, of FB-Forum ' ' -- compile with: -s console #Include "file.bi" Const As String ForumExt = ".B64" Function LoadFile( _ ByVal filen As String _ ) As String Dim As String text = "" If FileExists(filen) Then ' crash, if not existing! Var f = FreeFile If Open (filen For Binary Access Read As #f) = 0 Then If Lof(f) > 0 Then text = String(Lof(f), 0) Get #f,, text End If Close(f) Else Print "Unable to load: " + filen End If Else Print "File not existing: " + filen End If Return text End Function Sub SaveFile( _ ByVal filen As String, _ ByRef p As String _ ' string might be too large for ByVal ) var f = FreeFile If Open (filen For Binary Access Write As #f) = 0 Then If Len(p) > 0 Then Put #f,, p Close(f) Else Print "Unable to load: " + filen End If End Sub Function EncBase64( _ ' direction --> to forum ByRef iStr As Const String, _ ' source string-part ASCII ByVal n_sLen As UByte = 3 _ ' length of string-part (default = 3) ) As String ' base128 string-part Dim As UByte rmdr = 0, s_chr = 0 Dim As String s_stmp = iStr, t_sret = String(n_sLen, 0) For i As UInteger = 0 To n_sLen - 1 s_chr = s_stmp[i] ' get a byte, then check value If s_chr > 127 Then ' if leading bit is set, then rmdr = BitSet(rmdr, i) ' remember in "flags" byte s_chr -= 128 ' clear leading bit (MSbit) If s_chr > 63 Then ' second bit rmdr = BitSet(rmdr, i+3) ' 0 and 3 etc. s_chr -= 64 EndIf End If t_sret[i] = s_chr ' assign to return string Next t_sret += Chr(rmdr) ' add "flags" to string Return t_sret End Function Function DecBase64( _ ' direction <-- from forum ByRef iStr As Const String, _ ' as EncBase128 ByVal n_sLen As UByte = 4 _ ' string length with "flags" (+1) ) As String Dim As UByte rmdr = 0, s_chr = 0 Dim As String s_stmp = iStr, t_sret = String(n_sLen - 1, 0) rmdr = iStr[n_sLen - 1] ' save decoder byte "flags" For i As UInteger = 0 To n_sLen - 2 ' without decoder byte s_chr = s_stmp[i] ' get a byte If Bit(rmdr, i) Then s_chr += 128 ' check "flags" and set leading bit If Bit(rmdr, i+3) Then s_chr += 64 ' check "flags" and set second bit t_sret[i] = s_chr ' assign to return string Next Return t_sret End Function Function ShiftB64( _ ' ver 0.5 ByRef iStr As Const String _ ' source = ASCII string ) As String Dim As ULong n_run = Len(iStr) \ 3, n_rem = Len(iStr) Mod 3 Dim As UByte s_tchr = 0 Dim As String s_ret = "", s_tstr = "", s_estr = "" ' get encoded string (8 byte, from 7 byte "original") For i As UInteger = 0 To n_run - 1 Var sPos = i * 3 + 1 s_tstr = Mid(iStr, sPos, 3) s_ret += EncBase64(s_tstr) ' encode to 4 byte string Next ' string-end processing If n_rem > 0 Then Var sPos = n_run * 3 + 1 s_estr = Mid(iStr, sPos, n_rem) ' string remainder s_ret += EncBase64(s_estr, n_rem) ' encode rem. End If ' shift every byte to "printable", add 35 For j As UInteger = 0 To Len(s_ret) - 1 s_tchr = s_ret[j] + 35 ' apply shift s_ret[j] = s_tchr ' write back to string Next Return s_ret End Function Function ShiftASCII( _ ' ver 0.5 ByRef iStr As Const String _ ' source = B64 string ) As String Dim As ULong n_run = Len(iStr) \ 4, n_rem = Len(iStr) Mod 4 Dim As UByte s_tchr = 0 Dim As String s_ret = "", s_tstr = "", s_estr = "", s_tmp = iStr ' reverse shift to "B64 encoded" For j As UInteger = 0 To Len(s_tmp) - 1 s_tchr = s_tmp[j] - 35 ' get shifted byte & un-shift s_tmp[j] = s_tchr ' write un-shifted back Next ' get decoded string (4 byte chunks) For i As UInteger = 0 To n_run - 1 Var sPos = i * 4 + 1 s_tstr = Mid(s_tmp, sPos, 4) s_ret += DecBase64(s_tstr) ' decode string Next ' string-end processing (shorter than 4) If n_rem > 0 Then Var sPos = n_run * 4 + 1 s_estr = Mid(s_tmp, sPos, n_rem) ' string end s_ret += DecBase64(s_estr, n_rem) ' decode string end End If Return s_ret End Function Sub GetUserInput( _ ByRef sFle As String, _ ' file name (with or without ext) ByVal mode As UByte = 0 _ ' 0 = default +ext, 1 = no ext ) Dim As String q = "Please, enter INPUT file name: ", a ' question/answer strings (local) again: Line Input q, a ' ask for filename If a = "" Then GoTo again ' file name is mandatory! If mode = 1 AndAlso InStr(a, ".") Then ' ext check in mode = 1 only Color 12 : Print "File contains extension, enter filename without it! "; Sleep 1500, 1 : Color 7 : GoTo again End If If mode = 1 Then a += ForumExt ' add extension ".B128" sFle = a End Sub ' ===== MAIN ===== Width 120, 25 ' we might want a larger console window Dim As String sFile, sQuest, sAns, c, d, sDir = CurDir Dim As String sTitle = "ForumBlobPost - Utility, version 0.5 (BASE64)", _ uline = String(Len(sTitle), "-") start: Cls : Color 15 : Print sTitle : Print uline : Print : Color 7 sQuest = "enter the direction: to/from Forum [t|f] 'q = quit' : " Line Input sQuest, sAns ' line input accepts a string-var (input doesn't) ' evaluate user input Select Case As Const Asc(LCase(sAns), 1) ' check of first char only Case 102 Color 10 : Print "Enter filename *without* extension, please!" : Color 7 GetUserInput(sFile, 1) ' f/F entered, extension ".B128" assumed c = LoadFile(sFile) Var npos = InStr(c, Chr(34)) ' extract "original" filename, shorten d = Left(c, npos - 1) : c = Right(c, Len(c) - npos) ' source string Var r = ShiftASCII(c) ' decode SaveFile(d, r) ' ATTENTION: overwrites source file!!! Case 113 Print "quiting ..." : Sleep 750, 1 ' q/Q entered (user abort) Case 116 Color 11 : Print "Enter filename *with* extension, please!" : Color 7 GetUserInput(sFile) ' t/T entered, get source file Var dot = InStr(sFile, ".") ' get dot position d = Left(sFile, dot - 1) ' extract filename only If Len(d) > 0 Then ' check whether there is something d += ForumExt : c = LoadFile(sFile) ' add extension, then load it Else Print "File ERROR! " + d : Exit Select EndIf Var r = ShiftB64(c) : r = sFile + Chr(34) + r ' encode SaveFile(d, r) Case Else sAns = "" : Color 12 : Print "unrecognized command" ' in red Color 7 : Sleep 1500, 1 : GoTo start' all else (ask again) End Select Print : Print "Done ..." If CurDir <> sdir Then ChDir(sDir) ' restore path Sleep ' ===== END-MAIN ===== ' ----- EOF -----
Hm, yes, the easiest solution would be to allow attachments in this forum. I've no idea why this isn't allowed as the necessary storage for that shouldn't be expensive at all these days.leopardpm wrote:Thank you, Mr. Swiss - though I am disgusted that we can only utilize 6 bits of each forum byte for our transfer... seems so dang inefficient!
Well, yes and no.leopardpm wrote:... only utilize 6 bits of each forum byte for our transfer... seems so dang inefficient!
Agreed, but since it has been asked before (by other members) and, never got aSt_W wrote:... the easiest solution would be to allow attachments in this forum.
yes, of course it is more important to be cross-compatible... I was just wanting my cake and eat it too...MrSwiss wrote:Well, yes and no.leopardpm wrote:... only utilize 6 bits of each forum byte for our transfer... seems so dang inefficient!
Yes, its a shame to have 1/3 overhead.
No, the advantage, of not having to adapt to OS specific encoding mechanisms is,
as far as I'm concerned, just to big a benefit. (commonly known as: tradeoff)
yes.... now, if only WE could write a forum program in FB, the exact way we would like it... it could be BADASS! I could think of a thousand improvements as to how to better deal with threads that migrate off-topic, better, and more compact representation of posts (the 'quote' look takes up alot of screen space, makes for more user scrolling, etc), being able to attach images, being able to attach .EXE's that would be automatically virus scanned so folks could trust them more - having a section which would have completed projects and then the links to any threads pertaining to their development, etc... but the projects would be displayed and presented in a uniform way instead of in a regular thread... BUT, I am just 'wishing' here... right? or is it possible for us FB programmers to make a server-side program that throws up webpages and maintains databases of posts/attachments/etc...? Also, just remembered something about being able to 'run' FB code from within a webpage... would be nice to have a program posted and instead of copy/paste into an editor, just 'run' it from the browser whether or not FB was installed on the machine in question.... tricky feature!Agreed, but since it has been asked before (by other members) and, never got a response, it seems to be "the only possible workaround".St_W wrote:... the easiest solution would be to allow attachments in this forum.