Andrej Beresnyak. Fil'try v yuniksovskom Netscape
---------------------------------------------------------------
Origin: http://www.cco.caltech.edu/~andreyb/filters.html
Email: Andrey Beresnyak (andreyb@cco.caltech.edu)
Home page: http://www.cco.caltech.edu/~andreyb/
---------------------------------------------------------------
Nekotoroe vremya nazad, da i sejchas navernoe, veb brauzer myslilsya
kak nekij universal'nyj instrument, pozvolyayushchij raspoznavat' vse myslimye
formaty fajlov i kodirovki. Estestvenno, proizvoditeli brauzerov ne mogli
etogo obespechit', slishkom bystro razvivalas' Set', pridumyvalis' vse novye
i novye sposoby predstavleniya dannyh. V obhod problemy byli pridumany tri
sposoba, dva iz nih shiroko izvestny, a o tret'em i pojdet rech'.
Pervye dva upomyanutyh sposoba -- eto helpery (helpers) i plaginy (plugins).
Nedostatki helperov i plaginov
|to takoe helper? |to, po suti, ochen' prostaya shtuka. Brauzer skachivaet
fajl vo vremennuyu direktoriyu, zapuskaet nekoe absolyutno abstraktnoe prilozhenie
(helper) i peredaet emu etot fajl v kachestve argumenta. Inache govorya, delaet
to, chto my i sami mogli by sdelat' rukami, tol'ko potratili by na eto lishnyuyu
paru sekund. Poskol'ku vremennyj fajl mozhet kidat'sya v neizvestnoe vam mesto i
on udalyaetsya posle raboty helpera, mnogie predpochitayut zapuskat' helper
vruchnuyu. I pravil'no delayut. Takim obrazom, nikakih principial'no novyh uslug
mehanizm helperov nam ne predostavlyaet. On, mozhet byt', nemnozhko ekonomit
vremya.
Nedostatki etogo mehanizma ochevidny -- vo pervyh, brauzer zhdet, poka fajl
skachaetsya celikom i lish' potom zapuskaet helper. ZHdat' byvaet utomitel'no.
Pomnite, chem netskejp pobedil mozaiku? To-to zhe. Pravda, nekotorye hitrecy
pridumali obhod. Naprimer, vmesto togo, chtoby skachivat' celikom
Real Audio fajl (.ra) vam podsovyvayut fajl .ram, v kotorom lezhit lish' adres,
ukazyvayushchij na sam fajl so zvukom. Helper zapuskaetsya i potom sam beret
na sebya obyazannost' soedinyat'sya s serverom i skachivat' nuzhnye fajly. Takim
obrazom, sam helper stanovitsya malen'kim brauzerom. Rezul'tat -- helper
pribavlyaet v vese i vozmozhno dobavlyaet vam v sistemu novuyu dyrku.
Vo vtoryh, obyazannost' zakryt' helper posle raboty lezhit na vas zhe.
A esli ne hochet zakryvat'sya, pokazyvaet kakie-to debil'nye oshibki?
Brauzeru vse ravno -- eto teper' ne ego problema. On vam helper zapustil,
a vy uzh muchajtes'. A vozmozhnye bagi i dyry v bezopasnosti vseh etih
prilozhenij, kotorye nazapuskal brauzer? Opyat' zhe -- vashi problemy.
Plagin -- eto uzhe luchshe. |to takaya shtuka, kotoraya rabotaet v bolee
tesnom kontakte s brauzerom i v principe mozhet i pokazyvat' chto-to,
nesmotrya na to, chto ono eshche ne skachalos' (hotya akrobat, naprimer,
etogo ne delaet), i razmestitsya pryamo na veb-stranichke i t.p. i t.d.
Vot tol'ko takaya lyubopytnaya shtuka. U menya v brauzere stoit edinstvennyj
plagin -- Adobe Acrobat. Zapuskaetsya on kak tol'ko ya zagruzhayu kakoj-libo
.pdf fajl. A vygruzhaetsya kogda? Zapustite pered etim kakoj nibud'
task menedzher, naprimer top, i ponablyudajte. Dazhe esli ya nazhimayu na brauzere
knopku "back" akrobat i ne dumaet vygruzhatsya. On o svoej poleznosti slishkom
vysokogo mneniya. A esli pol'zovatel' obratno "forward" nazhmet? :)
Potom, u kazhdogo plagina -- svoe upravlenie, razbirajsya s nim kazhdyj raz.
A kak hotelos' by, skazhem, nazhat' za .zip fajl i chtob on sam raspakovalsya
i pokazal soderzhimoe pryamo v brauzere. Naskol'ko oblegchilas' by zhizn'
posetitelej knizhnoj polki "Russkoj fantastiki". A ved' est' takaya vozmozhnost'.
Pol'zovateli Unix-oidnogo Netscape-a, navernoe uzhe ponyali o chem rech'.
Nu, dlya nih ya i pishu. :) Da, v unix-ovskom netskejpe realizovan princip
fil'tra. Dokumenty, imeyushchie opredelennyj hider Content-encoding mogut
byt' propushcheny cherez fil'tr. Tak v netskejpe realizovano vstroennoe
ponimanie formatov gzip i compress -- standartnyh szhimal'shchikov fajlov
v yunikse. Kak eto sdelano? CHitaem fajl Netscape.ad:
! For those MIME content-encodings which are not directly understood
! internally, it is possible to specify another Unix program to use as
! a filter here.
!
! Each line in the encodingFilters resource consists of four fields,
! separated by colons and optional whitespace:
!
! : : :
!
! input-encoding: The MIME encoding from the Content-Transfer-Encoding header.
! (The basic encodings 7BIT, 8BIT, BINARY, BASE64, and QUOTED-
! PRINTABLE are built-in; no need to specify those.)
!
! output-encoding: The encoding that results from this transformation.
! Leaving this empty is usually appropriate.
!
! extensions: A comma-separated list of the extensions typically used for
! files in this encoding; if a document ends in one of these
! extensions, then when that document is saved to disk, the
! extension will be stripped off of the default file name
! (since documents are decoded before they are saved, and the
! extension would no longer accurately describe the file.)
!
! filter-command: A shell command which reads from stdin and writes to stdout
! which does the actual decoding.
!
*encodingFilters: \
x-compress : : .Z : uncompress -c \n\
compress : : .Z : uncompress -c \n\
x-gzip : : .z,.gz : gzip -cdq \n\
gzip : : .z,.gz : gzip -cdq \n
YA nemnogo poeksperimentiroval s etoj vozmozhnost'yu i vot rezul'taty.
Skazhem, u menya v fajle .Xresources (aka .Xdefaults) est' sleduyushchaya strochka
(perevody stroki ya poudalyal ot greha podal'she).
Netscape*encodingFilters: x-szip : : .sz : szip -d \n x-compress : : .Z : uncompress -c \n compress : : .Z : uncompress -c \n x-gzip : : .z,.gz : gzip -cdq \n gzip : : .z,.gz : gzip -cdq \n zip : : .zip : gunzip | recode -ak \n
Zamet'te -- starye fil'try tozhe nuzhno ostavit', a to propadet vozmozhnost'
smotret' .gz i .Z. Itak, chto nuzhno, chtob eta shtuka zarabotala, naprimer,
chtoby avtomaticheski raspakovyvalis' fajly, szhatye szip? Nuzhno, chtoby v hidere
peredavaemogo fajla .sz byla stroka "Content-encoding: x-szip". I vse.
K sozhaleniyu, nemnogie servery voobshche peredayut content-encoding. Tak chto
prakticheskoj pol'zy eta nahodka vryad li mnogo prineset. Razve chto zastavite
propuskat' za-gzip-lennye fajly eshche cherez kakoj-nibud' nuzhnyj vam fil'tr.
No vozmozhnosti to kakie, vozmozhnosti! Ved' dejstvitel'no raznyh tipov dannyh
sovsem nemnogo -- tekst, kartinka i zvuk. Zato raznyh formatov fajlov,
arhivatorov t'ma t'mushchaya. Skazhem, vmesto togo, chtoby zapuskat' helper,
prosmatrivayushchij Postscript fajl, postavit' fil'tr, vydirayushchij iz nego tekst
(takie est') i smotret' etot tekst pryamo v brauzere. Ili postavit' fil'tr,
perevodyashchij TeX v kakoj-nibud', pust' i krivoj, HTML.
Pishite, andreyb@cco.caltech.edu
Last-modified: Thu, 15 Jul 1999 07:42:35 GMT