Skip to main content
Commonmark migration
Source Link

On a linux system there's no need for special handling of devices. Just use the device file interface.

#Python 3 (byte strings) - 141 bytes

Python 3 (byte strings) - 141 bytes

d=input()
f=open(d,'r+b')
z=f.seek
z(0,2)
s=f.tell()
i=0
while i<2:
 z(0);f.write([b'\0',b'\xff'][i]*s);f.flush();z(0)
 if f.read()==x:i+=1

It's fairly straightforward, and not really optimised heavily, but it works. Here's a basic rundown.

  • Get input (device file path)
  • Open device file
  • Seek to the end, get filesize (block devices are always their real size)
  • enter write-and-check loop
  • construct 0-bit and 1-bit strings (x)
  • write bitstring
  • flush output (I could have set buffering=0 but this is shorter)
  • test file against x, and increment step of loop if it passes

exit loop when the increment is high enough

As a bonus, you could modify this for any set and number of byte-modification patterns, like 0x55/0xaa for stronger overwriting effects.

I did actually test this on a device file, using loopback. However, I'm not 100% sure the checking actually works. It might be necessary to close and reopen the file each pass, due to buffering behaviors. I would hope flush prevents this.

*edited to incorporate some suggestions in the comments

On a linux system there's no need for special handling of devices. Just use the device file interface.

#Python 3 (byte strings) - 141 bytes

d=input()
f=open(d,'r+b')
z=f.seek
z(0,2)
s=f.tell()
i=0
while i<2:
 z(0);f.write([b'\0',b'\xff'][i]*s);f.flush();z(0)
 if f.read()==x:i+=1

It's fairly straightforward, and not really optimised heavily, but it works. Here's a basic rundown.

  • Get input (device file path)
  • Open device file
  • Seek to the end, get filesize (block devices are always their real size)
  • enter write-and-check loop
  • construct 0-bit and 1-bit strings (x)
  • write bitstring
  • flush output (I could have set buffering=0 but this is shorter)
  • test file against x, and increment step of loop if it passes

exit loop when the increment is high enough

As a bonus, you could modify this for any set and number of byte-modification patterns, like 0x55/0xaa for stronger overwriting effects.

I did actually test this on a device file, using loopback. However, I'm not 100% sure the checking actually works. It might be necessary to close and reopen the file each pass, due to buffering behaviors. I would hope flush prevents this.

*edited to incorporate some suggestions in the comments

On a linux system there's no need for special handling of devices. Just use the device file interface.

Python 3 (byte strings) - 141 bytes

d=input()
f=open(d,'r+b')
z=f.seek
z(0,2)
s=f.tell()
i=0
while i<2:
 z(0);f.write([b'\0',b'\xff'][i]*s);f.flush();z(0)
 if f.read()==x:i+=1

It's fairly straightforward, and not really optimised heavily, but it works. Here's a basic rundown.

  • Get input (device file path)
  • Open device file
  • Seek to the end, get filesize (block devices are always their real size)
  • enter write-and-check loop
  • construct 0-bit and 1-bit strings (x)
  • write bitstring
  • flush output (I could have set buffering=0 but this is shorter)
  • test file against x, and increment step of loop if it passes

exit loop when the increment is high enough

As a bonus, you could modify this for any set and number of byte-modification patterns, like 0x55/0xaa for stronger overwriting effects.

I did actually test this on a device file, using loopback. However, I'm not 100% sure the checking actually works. It might be necessary to close and reopen the file each pass, due to buffering behaviors. I would hope flush prevents this.

*edited to incorporate some suggestions in the comments

another small modification, -2 bytes
Source Link

On a linux system there's no need for special handling of devices. Just use the device file interface.

#Python 3 (byte strings) - 143141 bytes

d=input()
f=open(d,'r+b')
z=f.seek
z(0,2)
s=f.tell()
i=0
while i<2:
 x=[b'\0',b'\xff'][i]*s;zz(0)f;f.write(x[b'\0',b'\xff'][i]*s);f.flush();z(0)
 if f.read()==x:i+=1

It's fairly straightforward, and not really optimised heavily, but it works. Here's a basic rundown.

  • Get input (device file path)
  • Open device file
  • Seek to the end, get filesize (block devices are always their real size)
  • enter write-and-check loop
  • construct 0-bit and 1-bit strings (x)
  • write bitstring
  • flush output (I could have set buffering=0 but this is shorter)
  • test file against x, and increment step of loop if it passes

exit loop when the increment is high enough

As a bonus, you could modify this for any set and number of byte-modification patterns, like 0x55/0xaa for stronger overwriting effects.

I did actually test this on a device file, using loopback. However, I'm not 100% sure the checking actually works. It might be necessary to close and reopen the file each pass, due to buffering behaviors. I would hope flush prevents this.

*edited to incorporate some suggestions in the comments

On a linux system there's no need for special handling of devices. Just use the device file interface.

#Python 3 (byte strings) - 143 bytes

d=input()
f=open(d,'r+b')
z=f.seek
z(0,2)
s=f.tell()
i=0
while i<2:
 x=[b'\0',b'\xff'][i]*s;z(0)f.write(x);f.flush();z(0)
 if f.read()==x:i+=1

It's fairly straightforward, and not really optimised heavily, but it works. Here's a basic rundown.

  • Get input (device file path)
  • Open device file
  • Seek to the end, get filesize (block devices are always their real size)
  • enter write-and-check loop
  • construct 0-bit and 1-bit strings (x)
  • write bitstring
  • flush output (I could have set buffering=0 but this is shorter)
  • test file against x, and increment step of loop if it passes

exit loop when the increment is high enough

As a bonus, you could modify this for any set and number of byte-modification patterns, like 0x55/0xaa for stronger overwriting effects.

I did actually test this on a device file, using loopback. However, I'm not 100% sure the checking actually works. It might be necessary to close and reopen the file each pass, due to buffering behaviors. I would hope flush prevents this.

*edited to incorporate some suggestions in the comments

On a linux system there's no need for special handling of devices. Just use the device file interface.

#Python 3 (byte strings) - 141 bytes

d=input()
f=open(d,'r+b')
z=f.seek
z(0,2)
s=f.tell()
i=0
while i<2:
 z(0);f.write([b'\0',b'\xff'][i]*s);f.flush();z(0)
 if f.read()==x:i+=1

It's fairly straightforward, and not really optimised heavily, but it works. Here's a basic rundown.

  • Get input (device file path)
  • Open device file
  • Seek to the end, get filesize (block devices are always their real size)
  • enter write-and-check loop
  • construct 0-bit and 1-bit strings (x)
  • write bitstring
  • flush output (I could have set buffering=0 but this is shorter)
  • test file against x, and increment step of loop if it passes

exit loop when the increment is high enough

As a bonus, you could modify this for any set and number of byte-modification patterns, like 0x55/0xaa for stronger overwriting effects.

I did actually test this on a device file, using loopback. However, I'm not 100% sure the checking actually works. It might be necessary to close and reopen the file each pass, due to buffering behaviors. I would hope flush prevents this.

*edited to incorporate some suggestions in the comments

added optimization suggestions and changed to bytes instead of chars
Source Link

On a linux system there's no need for special handling of devices. Just use the device file interface.

#Python 3 (byte strings) - 160 chars143 bytes

d=input("")
f=open(d,'r+b')
fz=f.seek
z(0,2)
s=f.tell() 
i=0
while i<2:
 x = [b'\x00'x=[b'\0',b'\xff'][i]*s:
 f.seekb'\xff'][i]*s;z(0)
 f.write(x)
 f;f.flush()
 f.seek;z(0)
 if f.read()==x:i+=1

It's fairly straightforward, and not really optimised heavily, but it works. Here's a basic rundown.

  • Get input (device file path)
  • Open device file
  • Seek to the end, get filesize (block devices are always their real size)
  • enter write-and-check loop
  • construct 0-bit and 1-bit strings (x)
  • write bitstring
  • flush output (I could have set buffering=0 but this is shorter)
  • test file against x, and increment step of loop if it passes

exit loop when the increment is high enough

As a bonus, you could modify this for any set and number of byte-modification patterns, like 0x55/0xaa for stronger overwriting effects.

I did actually test this on a device file, using loopback. However, I'm not 100% sure the checking actually works. It might be necessary to close and reopen the file each pass, due to buffering behaviors. I would hope flush prevents this.

*edited to incorporate some suggestions in the comments

On a linux system there's no need for special handling of devices. Just use the device file interface.

#Python 3 (byte strings) - 160 chars

d=input("")
f=open(d,'r+b')
f.seek(0,2)
s=f.tell() 
i=0
while i<2:
 x = [b'\x00',b'\xff'][i]*s:
 f.seek(0)
 f.write(x)
 f.flush()
 f.seek(0)
 if f.read()==x:i+=1

It's fairly straightforward, and not really optimised heavily, but it works. Here's a basic rundown.

  • Get input (device file path)
  • Open device file
  • Seek to the end, get filesize (block devices are always their real size)
  • enter write-and-check loop
  • construct 0-bit and 1-bit strings (x)
  • write bitstring
  • flush output (I could have set buffering=0 but this is shorter)
  • test file against x, and increment step of loop if it passes

exit loop when the increment is high enough

As a bonus, you could modify this for any set and number of byte-modification patterns, like 0x55/0xaa for stronger overwriting effects.

I did actually test this on a device file, using loopback. However, I'm not 100% sure the checking actually works. It might be necessary to close and reopen the file each pass, due to buffering behaviors. I would hope flush prevents this.

On a linux system there's no need for special handling of devices. Just use the device file interface.

#Python 3 (byte strings) - 143 bytes

d=input()
f=open(d,'r+b')
z=f.seek
z(0,2)
s=f.tell()
i=0
while i<2:
 x=[b'\0',b'\xff'][i]*s;z(0)f.write(x);f.flush();z(0)
 if f.read()==x:i+=1

It's fairly straightforward, and not really optimised heavily, but it works. Here's a basic rundown.

  • Get input (device file path)
  • Open device file
  • Seek to the end, get filesize (block devices are always their real size)
  • enter write-and-check loop
  • construct 0-bit and 1-bit strings (x)
  • write bitstring
  • flush output (I could have set buffering=0 but this is shorter)
  • test file against x, and increment step of loop if it passes

exit loop when the increment is high enough

As a bonus, you could modify this for any set and number of byte-modification patterns, like 0x55/0xaa for stronger overwriting effects.

I did actually test this on a device file, using loopback. However, I'm not 100% sure the checking actually works. It might be necessary to close and reopen the file each pass, due to buffering behaviors. I would hope flush prevents this.

*edited to incorporate some suggestions in the comments

added 43 characters in body
Source Link
Loading
Source Link
Loading